-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Fix #4247: Do not crash if self is of Array type #4251
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
case _ => | ||
ctx.error("Array type conflict with " + qual.symbol.name, tree.pos) | ||
defn.NothingType | ||
} |
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.
Scalac allows both the following:
class Foo[U] { self : Array[U] => self(0) }
class Foo[U] { self : Array[U] with Nothing =>
self.length
}
We need to justify why Dotty should deviate in such cases.
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.
We will never be able to instantiate a Foo because Array is final. The code is nonsensical as no subclass of Foo can mixin Array.
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.
I'm thinking it's the same case as def f(x: Nothing): Unit = 3
. The code is valid, though the function can not be called. If we have checks for realization of self types during instantiation, can we just reuse that mechanism?
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.
Maybe we could. But this patch should still be there to ensure there are no compiler crashes on arrays in case that checker fails to detect it early.
Also, It is possible that we may create some other kind of unrealisable array with something that is not the self type.
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.
I tend to agree with @liufengyun. We should fix https://github.com/lampepfl/dotty/blob/4c8a2bd319437f7ab22303a162f5922bc000134d/compiler/src/dotty/tools/dotc/typer/Checking.scala#L148
Otherwise we will reject class Foo[U] { self : Array[U] & Nothing => self(0) }
but accept class Foo[U] { self : Array[U] & Nothing => }
.
Also, It is possible that we may create some other kind of unrealisable array with something that is not the self type.
Wouldn't that be a bug? Then crashing is the right think to do
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 was a different issue.
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.
The & Nothing
is unrelated tho this particular issue.
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 was a different issue
Sorry, my point was that we should also reject test[U](x: Array[U] & Nothing) = x(0)
, if we reject self: Array[U] & Nothing => self(0)
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.
If we have checks for realization of self types during instantiation, can we just reuse that mechanism?
BTW, those checks on instantiation are spec-mandated (#4252), so I think I agree with @allanrenucci and @liufengyun.
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.
The check on instantiation are done and work as expected. The issue is that for this particular case we do have a problem before instantiation. This is a particular exception due to the way we erase Arrays into java arrays.
Additionally the self type Array is completely valid as far as this class is conserened and could be realizable. Though Array would be the only class that could extend it.
fd49b1d
to
0e64a0f
Compare
Rebased |
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.
Not sure about this one. It seems that we are masking a failure condition by an error, which can get us intro trouble easily. I'd prefer if we found and avoided the root cause instead.
No description provided.