-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Refactor tree type parameters #16298
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
Comments
I have a patch that does most of this (which I worked on as a good outcome from banning "an Old Paradox", #14820). |
Is #14820 correct? I don't see a connection. I have done the necessary changes now. It was surprisingly easy. PR forthcoming. |
The connection is that if that enforcement is in place you can trust that if a |
@dwijnand Ah yes, that makes sense. |
Compiler version
All 3.x versions
Minimized example
The modelling of ASTs can be improved by exploiting the
-Yexplicit-nulls
setting, which is enabled in the dotc build.There are the following major design criteria for AST trees, which should be kept:
T
.T = Type
and for untyped treesT = Untyped
whereUntyped
is eitherNull
orNothing
.typeOpt
method on trees returns aT
, i.e. either bottom type or aType
.tpe
method on trees returns aType
and will fail (ideally at compile time, but currently at runtime) if the tree is untyped.When
dotc
was first designed, we fulfilled the criteria by defining typeTree
like this:That made sure that typed trees
Tree[Type]
are a subtype of untyped treesTree[Null]
, sinceNull
was a subtype ofType
. But with explicit nulls, that's no longer true. So we changed the bottom type fromNull
toNothing
.Nevertheless, there's some awkwardness:
First, the
tpe
method on trees is variance incorrect. It is defined like this:Second, we can write
without problem even if
tree
is an untyped tree, since itstpe
method returnsNothing
, which conforms toType
.It looks like we can get a sound system with better static checking if we model
Tree
instead like this:It's going to be a big change in the sense of number of lines changed, but it would make things clearer. So I think we should do it before going into an LTS.
The text was updated successfully, but these errors were encountered: