-
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
Unsoundness: constructor params must not be in scope for the parent types #16270
Comments
@b-studios you opened an issue related to this pattern (path-dependent type on a constructor parameter) a while ago: #5636, did you end up using it in some project? If so, heads up that it's probably going away due to the unsoundness problem reported in this issue :). |
Hey, thanks :) Luckily we don't depend on it anymore. It was an experiment of embedding an effect system into Scala. Instead, we developed our own language ;) |
Ah I forgot about it but I'll try to get back to it before the milestone. |
Scala 3.3.0 does not allow the `extends` clause of a class to refer to constructor parameters. It was shown to be unsound. See scala/scala3#16270 However, we can depend on paths that enclose the class definition. So we introduce a container class `TreeMaps` that takes the `q: Q` as parameter, and move the classes that extend `q.reflect.TreeMap` inside that container.
Summary
It should not be legal to reference constructor parameters in the supertypes of a class:
Either of those two things can be used to create unsoundness in the form of a
ClassCastException
, as shown below.Fundamentally, the specification should reject those, as in either case, the linearization of
Evil
is ill-defined. Since the linearization is ill-defined, so isbaseType
, and everything falls down.Note that Scala 2 rejects both variants, at least as far back as 2.10.9. @smarter's thesis calculus does not include constructor parameters in the context when typing parent types either.
Compiler version
Today's
main
, commit 7fd161fMinimized code
First variant:
outer
in a type parameterSecond variant:
outer
in the path of the superclassThen run:
Output
Expectation
The compiler should reject either of those.
Scala 2 reports:
and
Credits
Collaboration with @shardulc and @smarter
The text was updated successfully, but these errors were encountered: