Skip to content

Fix more problems detected by fuzzing in #4389 #4411

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 13 commits into from
Apr 30, 2018
Merged
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/core/Types.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3478,7 +3478,7 @@ object Types {
if (selfTypeCache == null)
selfTypeCache = {
val given = cls.givenSelfType
if (!given.exists) appliedRef
if (!given.isValueType) appliedRef
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might be worth explicitly checking that an error happened like other commits in this PR do, e.g.:

if (!given.isValueType) {
  assert(!given.exists || ctx.reporter.errorsReported)
  appliedRef
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The given type might be higher-kinded (in fact that's what it was in the test) but this would be detected only later.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, in that case maybe just add a comment explaining that non-value types self can only happen with erroneous code? Otherwise readers of this code might be puzzled.

else if (cls is Module) given
else if (ctx.erasedTypes) appliedRef
else AndType(given, appliedRef)
Expand Down
6 changes: 6 additions & 0 deletions tests/neg/bad-selftype.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
trait x0[T] { self: x0 => } // error

trait x1[T] { self: (=> String) => } // error

trait x2[T] { self: ([X] => X) => } // error

2 changes: 2 additions & 0 deletions tests/neg/parser-stability-17.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
trait x0[] { x0: x0 => }
class x0[x1] extends x0[x0 x0] x2 x0