Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(#19402): error message for missing using in given params #19496

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

i10416
Copy link
Contributor

@i10416 i10416 commented Jan 20, 2024

close #19402

given-s can't have non-implicit arguments, but when users forget adding a using modifier to given parameters, it showed unfriendly error message; "only classes can have declared but undefined members".

The termParamClauses parser is aware of the owner of parameters and it raises a syntax error when parameters in given definition do not have using modifier with clear reason, but the condition in.token == LPAREN && in.lookahead.isIdent(nme.using) in Parsers.scala was too strict to delegate parameter clause handling to termParamClauses.

Note:
This change requires tests/neg/i8150.check to be updated because the original test starts failing due to the syntax error rather than "refinement cannot be given" error.

type T = {given A with A} in i8150.check confirms that a valid given definition in RHS of type alias still raises the original error; "refinement cannot be given" error.

`given`-s can't have non-implicit arguments, but when users forget
adding a `using` modifier to given parameters, it showed unfriendly error
message; "only classes can have declared but undefined members".

The `termParamClauses` parser is aware of the owner of parameters and it raises
a syntax error when parameters in given definition do not have `using` modifier with clear reason,
but `in.token == LPAREN && in.lookahead.isIdent(nme.using)` in
Parsers.scala was too strict to delegate parameter clause handling to `termParamClauses`.

Note:
This change requires tests/neg/i8150.check to be updated because the original
test starts failing due to the syntax error rather than "refinement cannot be `given`" error.

`type T = {given A with A}` in i8150.check confirms that a valid given definition
in RHS of type alias still raises the original error; "refinement cannot be `given`" error.
@odersky
Copy link
Contributor

odersky commented Feb 15, 2024

This will clash with the proposed syntax changes for type classes, which would make the change unnecessary. I therefore like to put this on hold until the fate of these syntax changes is decided.

@i10416 i10416 closed this Nov 14, 2024
@i10416 i10416 reopened this Nov 14, 2024
@odersky
Copy link
Contributor

odersky commented Jan 9, 2025

The syntax changes are now all stabilized. So @i10416, if you want to pick this up again, now it's all clear.

@odersky odersky assigned i10416 and unassigned odersky Jan 9, 2025
@i10416
Copy link
Contributor Author

i10416 commented Jan 9, 2025

Thank you for reminder!

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.

Confusing compiler errors when you forget the using keyword in given bar(using foo)
2 participants