Apoorv Ingle pushed to branch wip/spj-apporv-Oct24 at Glasgow Haskell Compiler / GHC Commits: 81d9fe03 by Apoorv Ingle at 2025-11-02T21:39:48-06:00 accept new test output - - - - - e75752ed by Apoorv Ingle at 2025-11-02T22:44:08-06:00 Do not use HsPar in Last statement - - - - - f556b226 by Apoorv Ingle at 2025-11-02T22:44:31-06:00 accept test cases - - - - - 21 changed files: - compiler/GHC/Tc/Gen/Do.hs - compiler/GHC/Tc/Gen/Head.hs - testsuite/tests/default/default-fail05.stderr - testsuite/tests/indexed-types/should_fail/T2693.stderr - testsuite/tests/overloadedrecflds/should_fail/T26480b.stderr - testsuite/tests/plugins/test-defaulting-plugin.stderr - testsuite/tests/polykinds/T13393.stderr - testsuite/tests/typecheck/should_compile/valid_hole_fits.stderr - testsuite/tests/typecheck/should_fail/T10971d.stderr - testsuite/tests/typecheck/should_fail/T13311.stderr - testsuite/tests/typecheck/should_fail/T24064.stderr - testsuite/tests/typecheck/should_fail/T3613.stderr - testsuite/tests/typecheck/should_fail/T6069.stderr - testsuite/tests/typecheck/should_fail/T7851.stderr - testsuite/tests/typecheck/should_fail/T8603.stderr - testsuite/tests/typecheck/should_fail/T9612.stderr - testsuite/tests/typecheck/should_fail/tcfail128.stderr - testsuite/tests/typecheck/should_fail/tcfail140.stderr - testsuite/tests/typecheck/should_fail/tcfail168.stderr - testsuite/tests/typecheck/should_fail/tcfail181.stderr - testsuite/tests/warnings/should_fail/CaretDiagnostics1.stderr Changes: ===================================== compiler/GHC/Tc/Gen/Do.hs ===================================== @@ -81,15 +81,15 @@ expand_do_stmts flav [stmt@(L sloc (LastStmt _ body@(L body_loc _) _ ret_expr))] -- See `checkLastStmt` and `Syntax.Expr.StmtLR.LastStmt` | NoSyntaxExprRn <- ret_expr -- Last statement is just body if we are not in ListComp context. See Syntax.Expr.LastStmt - = return $ L sloc (mkExpandedStmt stmt flav (HsPar noExtField body)) + = return $ L sloc (mkExpandedStmt stmt flav (unLoc body)) | SyntaxExprRn ret <- ret_expr -- We have unfortunately lost the location on the return function :( -- -- ------------------------------------------------ -- return e ~~> return e -- to make T18324 work - = do let expansion = L body_loc (genHsApp ret body) - return $ L sloc (mkExpandedStmt stmt flav (HsPar noExtField expansion)) + = do let expansion = HsApp noExtField (L body_loc ret) body + return $ L sloc (mkExpandedStmt stmt flav expansion) expand_do_stmts doFlavour (stmt@(L loc (LetStmt _ bs)) : lstmts) = -- See Note [Expanding HsDo with XXExprGhcRn] Equation (3) below ===================================== compiler/GHC/Tc/Gen/Head.hs ===================================== @@ -1119,6 +1119,9 @@ addExprCtxt e thing_inside addLExprCtxt :: LHsExpr GhcRn -> TcRn a -> TcRn a addLExprCtxt (L lspan e) thing_inside + | (RealSrcSpan{}) <- locA lspan + , (HsPar _ e') <- e + = addExprCtxt (unLoc e') thing_inside | (RealSrcSpan{}) <- locA lspan = addExprCtxt e thing_inside | otherwise ===================================== testsuite/tests/default/default-fail05.stderr ===================================== @@ -11,7 +11,7 @@ default-fail05.hs:11:10: error: [GHC-39999] (use -fprint-potential-instances to see them all) • In the first argument of ‘($)’, namely ‘toList’ In the first argument of ‘print’, namely ‘(toList $ pure 21)’ - In the expression: print (toList $ pure 21) + In a stmt of a 'do' block: print (toList $ pure 21) default-fail05.hs:11:19: error: [GHC-39999] • Ambiguous type variable ‘t0’ arising from a use of ‘pure’ @@ -25,10 +25,10 @@ default-fail05.hs:11:19: error: [GHC-39999] (use -fprint-potential-instances to see them all) • In the second argument of ‘($)’, namely ‘pure 21’ In the first argument of ‘print’, namely ‘(toList $ pure 21)’ - In the expression: print (toList $ pure 21) + In a stmt of a 'do' block: print (toList $ pure 21) default-fail05.hs:12:3: error: [GHC-39999] - • Ambiguous type variable ‘t1’ arising from a use of ‘traverse’ + • Ambiguous type variable ‘t1’ arising from a do statement prevents the constraint ‘(Traversable t1)’ from being solved. Relevant bindings include main :: IO (t1 ()) (bound at default-fail05.hs:10:1) ===================================== testsuite/tests/indexed-types/should_fail/T2693.stderr ===================================== @@ -42,8 +42,5 @@ T2693.hs:29:20: error: [GHC-83865] The type variable ‘a0’ is ambiguous • In the first argument of ‘mapM’, namely ‘g’ In the expression: mapM g undefined - In the expression: - do pvs <- mapM g undefined - let n = (map ...) `min` (map ...) - undefined + In a stmt of a 'do' block: pvs <- mapM g undefined ===================================== testsuite/tests/overloadedrecflds/should_fail/T26480b.stderr ===================================== @@ -42,7 +42,7 @@ T26480b.hs:43:12: error: [GHC-39999] T26480b.hs:47:10: error: [GHC-39999] • No instance for ‘HasField "xyzzywyzzydyzzd" G H’ - arising from the record selector ‘xyzzywyzzydyzzd’ + arising from the expression (.xyzzywyzzydyzzd) NB: ‘G’ does not have a record field named ‘xyzzywyzzydyzzd’. • In the expression: (.xyzzywyzzydyzzd) In an equation for ‘test3a’: test3a = (.xyzzywyzzydyzzd) @@ -50,6 +50,7 @@ T26480b.hs:47:10: error: [GHC-39999] T26480b.hs:50:10: error: [GHC-39999] • No instance for ‘HasField "xyzzywyzzydyzze" G H’ + arising from the expression (.field1.xyzzywyzzydyzze) NB: ‘G’ does not have a record field named ‘xyzzywyzzydyzze’. • In the expression: (.field1.xyzzywyzzydyzze) In an equation for ‘test3b’: test3b = (.field1.xyzzywyzzydyzze) @@ -66,6 +67,7 @@ T26480b.hs:54:12: error: [GHC-39999] T26480b.hs:57:12: error: [GHC-39999] • No instance for ‘HasField "xyzzywyzzydyzzg" G H’ + arising from a record update NB: ‘G’ does not have a record field named ‘xyzzywyzzydyzzg’. • In the expression: d {field1.xyzzywyzzydyzzg = MkH 3} In an equation for ‘test4b’: ===================================== testsuite/tests/plugins/test-defaulting-plugin.stderr ===================================== @@ -3,7 +3,7 @@ test-defaulting-plugin.hs:28:11: warning: [GHC-18042] [-Wtype-defaults (in -Wall KnownNat a0 arising from a use of ‘q’ • In the first argument of ‘(+)’, namely ‘q’ In the second argument of ‘($)’, namely ‘q + w’ - In the expression: print $ q + w + In a stmt of a 'do' block: print $ q + w test-defaulting-plugin.hs:28:15: warning: [GHC-18042] [-Wtype-defaults (in -Wall)] • Defaulting the type variable ‘a0’ to type ‘2’ in the following constraints @@ -15,7 +15,7 @@ test-defaulting-plugin.hs:28:15: warning: [GHC-18042] [-Wtype-defaults (in -Wall arising from a use of ‘w’ at test-defaulting-plugin.hs:28:15 • In the second argument of ‘(+)’, namely ‘w’ In the second argument of ‘($)’, namely ‘q + w’ - In the expression: print $ q + w + In a stmt of a 'do' block: print $ q + w test-defaulting-plugin.hs:29:11: warning: [GHC-18042] [-Wtype-defaults (in -Wall)] • Defaulting the type variable ‘b0’ to type ‘0’ in the following constraint ===================================== testsuite/tests/polykinds/T13393.stderr ===================================== @@ -1,25 +1,26 @@ T13393.hs:61:3: error: [GHC-39999] - • Ambiguous type variable ‘t0’ arising from a use of ‘mapM’ + • Ambiguous type variable ‘t0’ arising from a do statement prevents the constraint ‘(Traversable t0)’ from being solved. Probable fix: use a type annotation to specify what ‘t0’ should be. Potentially matching instances: - instance Traversable (Either a) - -- Defined in ‘GHC.Internal.Data.Traversable’ - instance Traversable Identity - -- Defined in ‘GHC.Internal.Data.Traversable’ - ...plus four others - ...plus 27 instances involving out-of-scope types - (use -fprint-potential-instances to see them all) - • In the expression: - mapM putBackLeftOverInputAndReturnOutput undefined + instance Traversable (Either a) + -- Defined in ‘GHC.Internal.Data.Traversable’ + instance Traversable Identity + -- Defined in ‘GHC.Internal.Data.Traversable’ + ...plus four others + ...plus 27 instances involving out-of-scope types + (use -fprint-potential-instances to see them all) + • In a stmt of a 'do' block: + mapM putBackLeftOverInputAndReturnOutput undefined In the expression: - do mapM putBackLeftOverInputAndReturnOutput undefined - undefined + do mapM putBackLeftOverInputAndReturnOutput undefined + undefined In an equation for ‘encodeLinearToAac’: - encodeLinearToAac - = do mapM putBackLeftOverInputAndReturnOutput undefined - undefined - where - putBackLeftOverInputAndReturnOutput (MkEncodeResult x) - = do leftOvers .= x - undefined + encodeLinearToAac + = do mapM putBackLeftOverInputAndReturnOutput undefined + undefined + where + putBackLeftOverInputAndReturnOutput (MkEncodeResult x) + = do leftOvers .= x + undefined + ===================================== testsuite/tests/typecheck/should_compile/valid_hole_fits.stderr ===================================== @@ -12,15 +12,11 @@ valid_hole_fits.hs:9:6: warning: [GHC-88464] [-Wdeferred-out-of-scope-variables valid_hole_fits.hs:17:17: warning: [GHC-88464] [-Wtyped-holes (in -Wdefault)] • Found hole: _ :: Int -> IO Int • In the expression: _ x + In a stmt of a 'do' block: y <- _ x In the expression: do x <- a 0 y <- _ x return y - In an equation for ‘c’: - c _ - = do x <- a 0 - y <- _ x - return y • Relevant bindings include x :: Int (bound at valid_hole_fits.hs:16:12) c :: Int -> IO Int (bound at valid_hole_fits.hs:16:1) ===================================== testsuite/tests/typecheck/should_fail/T10971d.stderr ===================================== @@ -3,14 +3,14 @@ T10971d.hs:4:14: error: [GHC-83865] with actual type: Maybe a3 • In the first argument of ‘f’, namely ‘(Just 1)’ In the second argument of ‘($)’, namely ‘f (Just 1)’ - In the expression: print $ f (Just 1) + In a stmt of a 'do' block: print $ f (Just 1) T10971d.hs:5:19: error: [GHC-83865] • Couldn't match expected type: [b0] with actual type: Maybe a4 • In the second argument of ‘g’, namely ‘(Just 5)’ In the second argument of ‘($)’, namely ‘g (+ 1) (Just 5)’ - In the expression: print $ g (+ 1) (Just 5) + In a stmt of a 'do' block: print $ g (+ 1) (Just 5) T10971d.hs:6:23: error: [GHC-83865] • Couldn't match expected type: [a2] ===================================== testsuite/tests/typecheck/should_fail/T13311.stderr ===================================== @@ -2,7 +2,7 @@ T13311.hs:9:3: error: [GHC-83865] • Couldn't match expected type: IO a0 with actual type: Maybe a1 -> Maybe b0 • Probable cause: ‘f’ is applied to too few arguments - In the expression: f + In a stmt of a 'do' block: f In the expression: do f putChar 'a' ===================================== testsuite/tests/typecheck/should_fail/T24064.stderr ===================================== @@ -10,7 +10,7 @@ T24064.hs:42:3: error: [GHC-25897] the type signature for: test :: forall (m :: * -> *). (C2 m, F2 m ~ Y) => m () at T24064.hs:40:1-32 - • In the expression: fun1 + • In a stmt of a 'do' block: fun1 In the expression: do fun1 fun2 ===================================== testsuite/tests/typecheck/should_fail/T3613.stderr ===================================== @@ -10,7 +10,7 @@ T3613.hs:17:24: error: [GHC-83865] • Couldn't match type ‘IO’ with ‘Maybe’ Expected: Maybe () Actual: IO () - • In the expression: bar + • In a stmt of a 'do' block: bar In the first argument of ‘fooThen’, namely ‘(do bar undefined)’ ===================================== testsuite/tests/typecheck/should_fail/T6069.stderr ===================================== @@ -1,4 +1,3 @@ - T6069.hs:13:15: error: [GHC-83865] • Couldn't match type: forall s. ST s b0 with: ST s0 Int @@ -24,4 +23,5 @@ T6069.hs:15:16: error: [GHC-83865] Actual: (forall s. ST s b2) -> b2 • In the second argument of ‘(.)’, namely ‘runST’ In the expression: print . runST - In the expression: ((print . runST) $) fourty_two + In the expression: (print . runST) $ + ===================================== testsuite/tests/typecheck/should_fail/T7851.stderr ===================================== @@ -2,7 +2,7 @@ T7851.hs:5:10: error: [GHC-83865] • Couldn't match expected type: IO a0 with actual type: a1 -> IO () • Probable cause: ‘print’ is applied to too few arguments - In the expression: print + In a stmt of a 'do' block: print In the expression: do print print "Hello" ===================================== testsuite/tests/typecheck/should_fail/T8603.stderr ===================================== @@ -10,7 +10,5 @@ T8603.hs:33:17: error: [GHC-18872] m a -> t m a’ has only one In the expression: lift uniform [1, 2, 3] - In the expression: - do prize <- lift uniform [1, 2, 3] - return False + In a stmt of a 'do' block: prize <- lift uniform [1, 2, 3] ===================================== testsuite/tests/typecheck/should_fail/T9612.stderr ===================================== @@ -3,9 +3,9 @@ T9612.hs:16:9: error: [GHC-18872] with: (Int, a) arising from a functional dependency between: constraint ‘MonadWriter (Int, a) (WriterT [(Int, a)] Identity)’ - arising from a use of ‘tell’ + arising from a do statement instance ‘MonadWriter w (WriterT w m)’ at T9612.hs:20:10-59 - • In the expression: tell (n, x) + • In a stmt of a 'do' block: tell (n, x) In the expression: do tell (n, x) return (1, y) ===================================== testsuite/tests/typecheck/should_fail/tcfail128.stderr ===================================== @@ -6,6 +6,7 @@ tcfail128.hs:18:16: error: [GHC-39999] one instance involving out-of-scope types (use -fprint-potential-instances to see them all) • In the expression: thaw tmp + In a stmt of a 'do' block: v <- thaw tmp In the expression: do let sL = [...] dim = length sL @@ -13,11 +14,4 @@ tcfail128.hs:18:16: error: [GHC-39999] ... v <- thaw tmp return () - In an equation for ‘main’: - main - = do let sL = ... - dim = length sL - ... - v <- thaw tmp - return () ===================================== testsuite/tests/typecheck/should_fail/tcfail140.stderr ===================================== @@ -17,7 +17,8 @@ tcfail140.hs:13:10: error: [GHC-83865] tcfail140.hs:15:15: error: [GHC-83865] • Couldn't match expected type ‘t -> b’ with actual type ‘Int’ - • In the first argument of ‘map’, namely ‘(3 `f`)’ + • Possible cause: ‘f’ is applied to too many arguments + In the first argument of ‘map’, namely ‘(3 `f`)’ In the expression: map (3 `f`) xs In an equation for ‘bot’: bot xs = map (3 `f`) xs • Relevant bindings include ===================================== testsuite/tests/typecheck/should_fail/tcfail168.stderr ===================================== @@ -1,19 +1,20 @@ tcfail168.hs:7:11: error: [GHC-83865] • Couldn't match expected type: IO a0 - with actual type: Char -> IO () + with actual type: Char -> IO () • Probable cause: ‘putChar’ is applied to too few arguments - In the expression: putChar + In a stmt of a 'do' block: putChar In the expression: - do putChar - putChar 'a' - putChar 'a' - putChar 'a' - putChar 'a' - ... + do putChar + putChar 'a' + putChar 'a' + putChar 'a' + putChar 'a' + ... In an equation for ‘foo’: - foo - = do putChar - putChar 'a' - putChar 'a' - putChar 'a' - ... + foo + = do putChar + putChar 'a' + putChar 'a' + putChar 'a' + ... + ===================================== testsuite/tests/typecheck/should_fail/tcfail181.stderr ===================================== @@ -1,6 +1,5 @@ - tcfail181.hs:17:9: error: [GHC-39999] - • Could not deduce ‘Monad m0’ arising from a use of ‘foo’ + • Could not deduce ‘Monad m0’ arising from a record update from the context: Monad m bound by the inferred type of wog :: Monad m => p -> Something (m Bool) e @@ -12,8 +11,9 @@ tcfail181.hs:17:9: error: [GHC-39999] ...plus six others ...plus one instance involving out-of-scope types (use -fprint-potential-instances to see them all) - • In the expression: foo - In a record update at field ‘bar’, + • In a record update at field ‘bar’, with type constructor ‘Something’ and data constructor ‘Something’. In the expression: foo {bar = return True} + In an equation for ‘wog’: wog x = foo {bar = return True} + ===================================== testsuite/tests/warnings/should_fail/CaretDiagnostics1.stderr ===================================== @@ -1,7 +1,7 @@ CaretDiagnostics1.hs:7:8-15: error: [GHC-83865] • Couldn't match expected type ‘IO a0’ with actual type ‘Int’ • In the second argument of ‘(+)’, namely ‘(3 :: Int)’ - In the expression: + In a stmt of a 'do' block: 10000000000000000000000000000000000000 + 2 + (3 :: Int) In the expression: do 10000000000000000000000000000000000000 + 2 + (3 :: Int) View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/dc871fb970034810dc8854affdd642c... -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/dc871fb970034810dc8854affdd642c... You're receiving this email because of your account on gitlab.haskell.org.