Skip to content
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

Fix/#692 transitive selfrefs #702

Merged
merged 3 commits into from
Jul 6, 2015

Conversation

odersky
Copy link
Contributor

@odersky odersky commented Jun 28, 2015

This was a longer thread than I expected. Review by @DarkDimius


private def otherReason(pre: Type)(implicit ctx: Context): String = pre match {
case pre: ThisType if pre.givenSelfType.exists =>
i"\nor the self type of $pre might not contain all transitive dependencies"
Copy link
Member

Choose a reason for hiding this comment

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

Typo: "nor" -> "or"

Copy link
Contributor

Choose a reason for hiding this comment

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

isn't \n here an escaped "end of line" character?

Copy link
Member

Choose a reason for hiding this comment

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

Ah, you're right, I misread that.

@DarkDimius
Copy link
Contributor

LGTM, needs rebasing.

odersky added 3 commits July 6, 2015 16:55
In the type `(A & B)(C.this)`, the first parens were missing, so the type
displayed as A & B(C.this), which is confusing.
A TypeRef can have be unresolved, either because it refers to something that's missing
from the classpath or because of transitive self type references. Instead of crashing
in sigName, we now report the error.

Achieved by defining a new exception type, MissingType, which derives from TypeError.

This catches t7933.scala, now integrated in the neg/selfreq.scala. The problem there was
a reference to AbsSettings, which was not a member of StandardScalaSettings.this,
but was a member of the required type of AbsSettings, which itself appeared in the
required type of StandardScalaSettings. We will outlaw in the next commit such transitive
required references.

Also collapsed TypeError and FatalTypeError. It was a misnomer anyway. Fatal were those
type errors that were caught and reported!

Open: Where else we should check for unresolved NamedTypes.
What is checked: A self type T is a subtype of all
selftypes of classes refernced by T. That is, a self type
has to subsume all self types of its required type. Ot,
otherwise said, requirements must be closed; you cannot
discover new ones in following them.
@odersky odersky force-pushed the fix/#692-transitive-selfrefs branch from 40cd899 to 1754995 Compare July 6, 2015 15:12
@odersky
Copy link
Contributor Author

odersky commented Jul 6, 2015

Rebased to master

odersky added a commit that referenced this pull request Jul 6, 2015
@odersky odersky merged commit 6561d4c into scala:master Jul 6, 2015
@odersky
Copy link
Contributor Author

odersky commented Jul 6, 2015

Closes #690

@allanrenucci allanrenucci deleted the fix/#692-transitive-selfrefs branch December 14, 2017 19:21
odersky added a commit to dotty-staging/dotty that referenced this pull request Jan 10, 2023
scala#702 introduced a requirement that self types are closed. This means

> If trait X has self type S and C is a class symbol of S, then S also conforms
to the self type of C.

An example that violates this requirement is
```scala
trait X { self: Y => } // error: missing requirement: self type Y & X of trait X does not conform to self type Z of required trait Y
trait Y { self: Z => }
trait Z
```
But it's no longer clear what the requirement should achieve. If we let the example above
typecheck and try to implement X with something like
```scala
class C extends X, Y
```
we would at that point get an error saying that `C` does not conform to the self type Z of Y.
So it would have to be
```scala
class C extends X, Y, Z
```
and this one looks fine.

The original change in scala#702 was made to avoid a crash in pending/run/t7933.scala.
Unfortunately, we cannot reproduce this anymore since it depends on nsc.interpreter,
which is no longer part of Scala 2.13.

Since we are no longer sure what the restriction should achieve I think it's better to
drop it for now. If people discover problems with code that uses "open" self types, we
can try to fix those problems, and if that does not work, would fallback re-instituting
the restriction. It's not ideal, but I don't see another way.
odersky added a commit to dotty-staging/dotty that referenced this pull request Jan 10, 2023
scala#702 introduced a requirement that self types are closed. This means

> If trait X has self type S and C is a class symbol of S, then S also conforms
to the self type of C.

An example that violates this requirement is
```scala
trait X { self: Y => } // error: missing requirement: self type Y & X of trait X does not conform to self type Z of required trait Y
trait Y { self: Z => }
trait Z
```
But it's no longer clear what the requirement should achieve. If we let the example above
typecheck and try to implement X with something like
```scala
class C extends X, Y
```
we would at that point get an error saying that `C` does not conform to the self type Z of Y.
So it would have to be
```scala
class C extends X, Y, Z
```
and this one looks fine.

The original change in scala#702 was made to avoid a crash in pending/run/t7933.scala.
Unfortunately, we cannot reproduce this anymore since it depends on nsc.interpreter,
which is no longer part of Scala 2.13.

Since we are no longer sure what the restriction should achieve I think it's better to
drop it for now. If people discover problems with code that uses "open" self types, we
can try to fix those problems, and if that does not work, would fallback re-instituting
the restriction. It's not ideal, but I don't see another way.
odersky added a commit to dotty-staging/dotty that referenced this pull request Jan 11, 2023
scala#702 introduced a requirement that self types are closed. This means

> If trait X has self type S and C is a class symbol of S, then S also conforms
to the self type of C.

An example that violates this requirement is
```scala
trait X { self: Y => } // error: missing requirement: self type Y & X of trait X does not conform to self type Z of required trait Y
trait Y { self: Z => }
trait Z
```
But it's no longer clear what the requirement should achieve. If we let the example above
typecheck and try to implement X with something like
```scala
class C extends X, Y
```
we would at that point get an error saying that `C` does not conform to the self type Z of Y.
So it would have to be
```scala
class C extends X, Y, Z
```
and this one looks fine.

The original change in scala#702 was made to avoid a crash in pending/run/t7933.scala.
Unfortunately, we cannot reproduce this anymore since it depends on nsc.interpreter,
which is no longer part of Scala 2.13.

Since we are no longer sure what the restriction should achieve I think it's better to
drop it for now. If people discover problems with code that uses "open" self types, we
can try to fix those problems, and if that does not work, would fallback re-instituting
the restriction. It's not ideal, but I don't see another way.
odersky added a commit to dotty-staging/dotty that referenced this pull request Jan 11, 2023
scala#702 introduced a requirement that self types are closed. This means

> If trait X has self type S and C is a class symbol of S, then S also conforms
to the self type of C.

An example that violates this requirement is
```scala
trait X { self: Y => } // error: missing requirement: self type Y & X of trait X does not conform to self type Z of required trait Y
trait Y { self: Z => }
trait Z
```
But it's no longer clear what the requirement should achieve. If we let the example above
typecheck and try to implement X with something like
```scala
class C extends X, Y
```
we would at that point get an error saying that `C` does not conform to the self type Z of Y.
So it would have to be
```scala
class C extends X, Y, Z
```
and this one looks fine.

The original change in scala#702 was made to avoid a crash in pending/run/t7933.scala.
Unfortunately, we cannot reproduce this anymore since it depends on nsc.interpreter,
which is no longer part of Scala 2.13.

Since we are no longer sure what the restriction should achieve I think it's better to
drop it for now. If people discover problems with code that uses "open" self types, we
can try to fix those problems, and if that does not work, would fallback re-instituting
the restriction. It's not ideal, but I don't see another way.
odersky added a commit that referenced this pull request Jan 12, 2023
#702 introduced a requirement that self types are closed. This means

> If trait X has self type S and C is a class symbol of S, then S also
conforms
to the self type of C.

An example that violates this requirement is
```scala
trait X { self: Y => } // error: missing requirement: self type Y & X of trait X does not conform to self type Z of required trait Y
trait Y { self: Z => }
trait Z
```
But it's no longer clear what the requirement should achieve. If we let
the example above typecheck and try to implement X with something like
```scala
class C extends X, Y
```
we would at that point get an error saying that `C` does not conform to
the self type Z of Y. So it would have to be
```scala
class C extends X, Y, Z
```
and this one looks fine.

The original change in #702 was made to avoid a crash in
pending/run/t7933.scala. Unfortunately, we cannot reproduce this anymore
since it depends on nsc.interpreter, which is no longer part of Scala
2.13.

Since we are no longer sure what the restriction should achieve I think
it's better to drop it for now. If people discover problems with code
that uses "open" self types, we can try to fix those problems, and if
that does not work, would fallback re-instituting the restriction. It's
not ideal, but I don't see another way.

Fixes #16407
little-inferno pushed a commit to little-inferno/dotty that referenced this pull request Jan 25, 2023
scala#702 introduced a requirement that self types are closed. This means

> If trait X has self type S and C is a class symbol of S, then S also conforms
to the self type of C.

An example that violates this requirement is
```scala
trait X { self: Y => } // error: missing requirement: self type Y & X of trait X does not conform to self type Z of required trait Y
trait Y { self: Z => }
trait Z
```
But it's no longer clear what the requirement should achieve. If we let the example above
typecheck and try to implement X with something like
```scala
class C extends X, Y
```
we would at that point get an error saying that `C` does not conform to the self type Z of Y.
So it would have to be
```scala
class C extends X, Y, Z
```
and this one looks fine.

The original change in scala#702 was made to avoid a crash in pending/run/t7933.scala.
Unfortunately, we cannot reproduce this anymore since it depends on nsc.interpreter,
which is no longer part of Scala 2.13.

Since we are no longer sure what the restriction should achieve I think it's better to
drop it for now. If people discover problems with code that uses "open" self types, we
can try to fix those problems, and if that does not work, would fallback re-instituting
the restriction. It's not ideal, but I don't see another way.
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