-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Improve opaque type with no RHS error message #15285
Conversation
It turns out this isn't the first time we've had issues with missing RHS of an opaque type, we have opaque type i0 // error: opaque type must be an alias type
opaque type i2 <: Int // error: opaque type must be an alias type
opaque type i1[_] // error: opaque type must be an alias type
opaque type x[_] <: Int // error: opaque type must be an alias type At one point the error message was as shown above, but this test has no check file, so the loss in clarity may not have been noticed at the time it was introduced. More relevant for this PR, the new output for the above test is -- Error: tests/neg/i6055.scala:1:12 -------------------------------------------
1 |opaque type i0 // error: opaque type must be an alias type
|^^^^^^^^^^^^^^
|opaque type must have a right-hand side
-- Error: tests/neg/i6055.scala:2:12 -------------------------------------------
2 |opaque type i2 <: Int // error: opaque type must be an alias type
|^^^^^^^^^^^^^^^^^^^^^
|opaque type must have a right-hand side
-- [E156] Syntax Error: tests/neg/i6055.scala:4:12 -----------------------------
4 |opaque type i1[_] // error: opaque type must be an alias type
|^^^^^^^^^^^^^^^^^
|Modifier opaque is not allowed for this definition
-- [E156] Syntax Error: tests/neg/i6055.scala:5:12 -----------------------------
5 |opaque type x[_] <: Int // error: opaque type must be an alias type
|^^^^^^^^^^^^^^^^^^^^^^^
|Modifier opaque is not allowed for this definition We should enhance the checking to recurse on LambdaTypeTree nodes so we detect the missing RHS on higher-kinded opaque types. |
if !tree.mods.is(Opaque) then tree | ||
else tree match | ||
case TypeDef(_, bounds: TypeBoundsTree) if bounds.alias.isEmpty => | ||
report.error(i"opaque type must have a right-hand side", tree.srcPos) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
report.error(i"opaque type must have a right-hand side", tree.srcPos) | |
report.error(i"opaque type must have a right-hand side", tree.srcPos.endPos) |
...if we want the caret to be placed where the missing RHS should go?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Both approaches seem reasonable to me. I do not have a preference on either option.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Both approaches seem reasonable to me. I do not have a preference on either option.
I pushed a commit to do this. |
Fixes #15266
Done in the spree with @griggt and @mtk