Skip to content

Resolve qualified constructor access on same-name-constructor types#429

Merged
rodrigogribeiro merged 1 commit into
argotorg:mainfrom
axic:same-name-adt
Jun 4, 2026
Merged

Resolve qualified constructor access on same-name-constructor types#429
rodrigogribeiro merged 1 commit into
argotorg:mainfrom
axic:same-name-adt

Conversation

@axic

@axic axic commented Jun 2, 2026

Copy link
Copy Markdown
Contributor

When a data type T has a same-name constructor (e.g. data Error = Error(word) | Empty | ...), the inner resolver for the bare receiver @Error@ in @Error.Empty@ eagerly produced @Con (QualName Error Error) []@. The outer ExpVar/ExpName resolver only matched @Just (Var d)@ for qualifier-style access, so it fell through to the catch-all and reported "Unqualified constructor: Empty. Use Type.Constructor form." — even though the user had used the qualified form.

Treat a same-name no-arg constructor receiver as if it were @Var d@ before dispatching on the case table, restoring the qualifier-handling paths for @Error.Empty@ and @Error.Msg(x)@.

Fixes #430

When a data type T has a same-name constructor (e.g. data Error =
Error(word) | Empty | ...), the inner resolver for the bare receiver
@error@ in @Error.Empty@ eagerly produced @con (QualName Error Error)
[]@. The outer ExpVar/ExpName resolver only matched @just (Var d)@ for
qualifier-style access, so it fell through to the catch-all and reported
"Unqualified constructor: Empty. Use Type.Constructor form." — even
though the user had used the qualified form.

Treat a same-name no-arg constructor receiver as if it were @var d@
before dispatching on the case table, restoring the qualifier-handling
paths for @Error.Empty@ and @Error.Msg(x)@.
-- the inner resolver eagerly produces @Con (QualName Error Error) []@ for the
-- bare name. Treat that shape as if it were @Var Error@ when it appears in
-- qualifier position so the outer qualifier-handling cases still match.
unwrapQualifierReceiver :: Maybe (Exp Name) -> Maybe (Exp Name)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have no clue about this "fix", but it does work.

@rodrigogribeiro rodrigogribeiro left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

@rodrigogribeiro rodrigogribeiro merged commit 4daf5aa into argotorg:main Jun 4, 2026
4 checks passed
@axic axic deleted the same-name-adt branch June 4, 2026 15:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Cannot use other variants of Error in std

3 participants