-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Fix checks related to value classes #1682
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
Conversation
771524e
to
48ceaaf
Compare
@@ -720,6 +720,9 @@ object RefChecks { | |||
case List(param) => | |||
if (param.is(Mutable)) | |||
ctx.error("value class parameter must not be a var", param.pos) | |||
|
|||
if (isDerivedValueClass(param.info.typeSymbol)) | |||
ctx.error("value class may not wrap another user-defined value class", param.pos) |
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.
No. That's completely fine and supported in Dotty. The only issue is when there is a cycle, this happens a value class underlying type (or the underlying type of its underlying type or ...) is the class itself. There is a checkNonCyclic
method in ExtensionMethods
that is supposed to do this but is currently disabled, try enabling it:
https://github.com/lampepfl/dotty/blob/master/src/dotty/tools/dotc/transform/ExtensionMethods.scala#L148-L150
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.
Thanks for the catch @smarter , I'm going to enable that.
Otherwise LGTM |
@@ -135,7 +135,7 @@ class TreeChecker extends Phase with SymTransformer { | |||
} | |||
} | |||
|
|||
class Checker(phasesToCheck: Seq[Phase]) extends ReTyper { | |||
class Checker(phasesToCheck: Seq[Phase]) extends ReTyper with NoChecking { |
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.
That's a drastic change. Why disable all checking in TreeChecker?
If it's just checkDerivedValue class that should be disabled during tree checking then it's better to
override that method directly.
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.
@odersky this is now addressed in the latest commit.
/rebuild |
LGTM |
Fix checks related to value classes: #1670 #1642
Note: despite the discussion today, the simplest fix is to move some
RefChecks
totyper
. The TODO comment in the typer already points the direction for the migration:And I'd argue the complexity is manageable -- typer is not becoming more complex. And having checks earlier simplifies error handling and later processing.
Review @odersky .