[Git][ghc/ghc][wip/spj-apporv-Oct24] enable NB for custom, user written HasField constraint errors
Apoorv Ingle pushed to branch wip/spj-apporv-Oct24 at Glasgow Haskell Compiler / GHC Commits: 2a4c6ed5 by Apoorv Ingle at 2026-01-12T14:39:20-06:00 enable NB for custom, user written HasField constraint errors - - - - - 5 changed files: - compiler/GHC/Tc/Errors.hs - compiler/GHC/Tc/Utils/Monad.hs - testsuite/tests/parser/should_fail/RecordDotSyntaxFail10.stderr - testsuite/tests/parser/should_fail/RecordDotSyntaxFail13.stderr - testsuite/tests/parser/should_fail/RecordDotSyntaxFail8.stderr Changes: ===================================== compiler/GHC/Tc/Errors.hs ===================================== @@ -81,6 +81,8 @@ import qualified GHC.Data.Strict as Strict import Language.Haskell.Syntax.Basic (FieldLabelString(..)) +import Language.Haskell.Syntax (HsExpr (RecordUpd, HsGetField, HsProjection)) +import GHC.Hs.Expr (SrcCodeOrigin(..)) import Control.Monad ( unless, when, foldM, forM_ ) import Data.Bifunctor ( bimap ) @@ -2685,6 +2687,10 @@ isHasFieldOrigin = \case RecordUpdOrigin {} -> True RecordFieldProjectionOrigin {} -> True GetFieldOrigin {} -> True + ExpansionOrigin (OrigExpr e) + | HsGetField{} <- e -> True + | RecordUpd{} <- e -> True + | HsProjection{} <- e -> True _ -> False ----------------------- ===================================== compiler/GHC/Tc/Utils/Monad.hs ===================================== @@ -1079,7 +1079,7 @@ setSrcSpan :: SrcSpan -> TcRn a -> TcRn a setSrcSpan (RealSrcSpan loc _) thing_inside = updLclCtxt (\env -> env { tcl_loc = loc }) thing_inside -setSrcSpan loc thing_inside +setSrcSpan _ thing_inside = thing_inside getSrcCodeOrigin :: TcRn (Maybe SrcCodeOrigin) ===================================== testsuite/tests/parser/should_fail/RecordDotSyntaxFail10.stderr ===================================== @@ -1,9 +1,15 @@ RecordDotSyntaxFail10.hs:40:11: error: [GHC-39999] • No instance for ‘HasField "quux" Quux String’ + arising from a record update NB: ‘HasField’ is not the built-in ‘GHC.Internal.Records.HasField’ class. • In the second argument of ‘($)’, namely ‘a {foo.bar.baz.quux}’ - In a stmt of a 'do' block: print $ a {foo.bar.baz.quux} In the expression: - do let a = Foo {foo = ...} - let quux = "Expecto patronum!" - print $ a {foo.bar.baz.quux} + do let a = Foo {foo = ...} + let quux = "Expecto patronum!" + print $ a {foo.bar.baz.quux} + In an equation for ‘main’: + main + = do let a = ... + let quux = "Expecto patronum!" + print $ a {foo.bar.baz.quux} + ===================================== testsuite/tests/parser/should_fail/RecordDotSyntaxFail13.stderr ===================================== @@ -3,8 +3,11 @@ RecordDotSyntaxFail13.hs:26:11: error: [GHC-39999] arising from a record update NB: ‘HasField’ is not the built-in ‘GHC.Internal.Records.HasField’ class. • In the second argument of ‘($)’, namely ‘a {foo}’ - In a stmt of a 'do' block: print $ a {foo} In the expression: do let a = Foo {foo = 12} print $ a {foo} + In an equation for ‘main’: + main + = do let a = ... + print $ a {foo} ===================================== testsuite/tests/parser/should_fail/RecordDotSyntaxFail8.stderr ===================================== @@ -3,7 +3,6 @@ RecordDotSyntaxFail8.hs:47:17: error: [GHC-39999] arising from selecting the field ‘quux1’ NB: ‘HasField’ is not the built-in ‘GHC.Internal.Records.HasField’ class. • In the second argument of ‘($)’, namely ‘....bar.baz.quux1’ - In a stmt of a 'do' block: print @Quux $ ....baz.quux1 In the expression: do let a = Foo {foo = ...} print @Quux $ ....quux1 @@ -11,13 +10,19 @@ RecordDotSyntaxFail8.hs:47:17: error: [GHC-39999] print @Quux $ b.quux2 let c = Foo {foo = ...} ... + In an equation for ‘main’: + main + = do let a = ... + print @Quux $ ....quux1 + let b = myQuux + print @Quux $ b.quux2 + ... RecordDotSyntaxFail8.hs:50:17: error: [GHC-39999] • No instance for ‘HasField "quux2" Quux Quux’ arising from selecting the field ‘quux2’ NB: ‘HasField’ is not the built-in ‘GHC.Internal.Records.HasField’ class. • In the second argument of ‘($)’, namely ‘b.quux2’ - In a stmt of a 'do' block: print @Quux $ b.quux2 In the expression: do let a = Foo {foo = ...} print @Quux $ ....quux1 @@ -25,12 +30,31 @@ RecordDotSyntaxFail8.hs:50:17: error: [GHC-39999] print @Quux $ b.quux2 let c = Foo {foo = ...} ... + In an equation for ‘main’: + main + = do let a = ... + print @Quux $ ....quux1 + let b = myQuux + print @Quux $ b.quux2 + ... RecordDotSyntaxFail8.hs:53:17: error: [GHC-39999] - • No instance for ‘HasField "quux3" Quux r0’ + • No instance for ‘HasField "quux3" Quux a0’ arising from selecting the field ‘quux3’ NB: ‘HasField’ is not the built-in ‘GHC.Internal.Records.HasField’ class. • In the expression: ....bar.baz.quux3 - In the second argument of ‘($)’, namely ‘....baz.quux3.wob’ - In a stmt of a 'do' block: print @Bool $ ....quux3.wob + In the expression: + do let a = Foo {foo = ...} + print @Quux $ ....quux1 + let b = myQuux + print @Quux $ b.quux2 + let c = Foo {foo = ...} + ... + In an equation for ‘main’: + main + = do let a = ... + print @Quux $ ....quux1 + let b = myQuux + print @Quux $ b.quux2 + ... View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/2a4c6ed571842a9fef2c486e675ab7e7... -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/2a4c6ed571842a9fef2c486e675ab7e7... You're receiving this email because of your account on gitlab.haskell.org.
participants (1)
-
Apoorv Ingle (@ani)