Skip to content

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

Merged
merged 7 commits into from
Dec 15, 2016
Merged

Conversation

liufengyun
Copy link
Contributor

Fix checks related to value classes: #1670 #1642

Note: despite the discussion today, the simplest fix is to move some RefChecks to typer. The TODO comment in the typer already points the direction for the migration:

+
+
+    // check value class constraints
+    RefChecks.checkDerivedValueClass(cls, body1)
+
     cdef1

     // todo later: check that
     //  1. If class is non-abstract, it is instantiatable:
     //  - self type is s supertype of own type
     //  - all type members have consistent bounds
     // 2. all private type members have consistent bounds
     // 3. Types do not override classes.
     // 4. Polymorphic type defs override nothing.

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 .

@liufengyun liufengyun force-pushed the vclass branch 2 times, most recently from 771524e to 48ceaaf Compare November 7, 2016 23:13
@@ -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)
Copy link
Member

@smarter smarter Nov 7, 2016

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

Copy link
Contributor Author

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.

@odersky
Copy link
Contributor

odersky commented Nov 10, 2016

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 {
Copy link
Contributor

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.

Copy link
Contributor Author

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.

@liufengyun
Copy link
Contributor Author

/rebuild

@odersky
Copy link
Contributor

odersky commented Dec 15, 2016

LGTM

@odersky odersky merged commit 9f2b5ad into scala:master Dec 15, 2016
@liufengyun liufengyun deleted the vclass branch December 15, 2016 17:02
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.

4 participants