-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Explain unresolvable references better
We run into problems when referring to a member of a self type of a class that it not also a member of the class from outside via an asSeenFrom. One example is in 11226.scala where we see: ```scala trait ManagedActorClassification { this: ActorEventBus => def unsubscribe(subscriber: Subscriber): Unit } class Unsubscriber(bus: ManagedActorClassification) { def test(a: ActorRef): Unit = bus.unsubscribe(a) // error } ``` The problem is that `unsubscribe` refers to the type `Subscriber` which is not resolvable as a member of `bus`. one idea could be to rule out type signatures like `unsubscribe`, similar how we rule out public signatures referring to private members. But this could rule out existing valid programs. For instance, the `unsubscribe` signature is unproblematic if it gets only called with prefixes that inherit `ActorEventBus`. You could say that the problem was instead that the type of `bus` was not specific enough. In the long term, maybe restructing the signature is the right move. But for now, we just try to give better error messages in the case of existing failures. Fixes #11226
- Loading branch information
Showing
8 changed files
with
94 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
-- Error: tests/neg/i11226.scala:13:36 --------------------------------------------------------------------------------- | ||
13 | def test(a: ActorRef): Unit = bus.unsubscribe(a) // error | ||
| ^ | ||
| Cannot resolve reference to type (Unsubscriber.this.bus : ManagedActorClassification).Subscriber. | ||
| Subscriber exists as a member of the self type ActorEventBus of trait ManagedActorClassification | ||
| but it cannot be referenced from a scope that does not extend that trait. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
trait ActorRef | ||
|
||
trait ActorEventBus { | ||
type Subscriber = ActorRef | ||
} | ||
|
||
trait ManagedActorClassification { this: ActorEventBus => | ||
def unsubscribe(subscriber: Subscriber, from: Any): Unit | ||
def unsubscribe(subscriber: Subscriber): Unit | ||
} | ||
|
||
class Unsubscriber(bus: ManagedActorClassification) { | ||
def test(a: ActorRef): Unit = bus.unsubscribe(a) // error | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
-- [E007] Type Mismatch Error: tests/neg/i11226a.scala:12:48 ----------------------------------------------------------- | ||
12 | def test(a: ActorRef): Unit = bus.unsubscribe(a) // error | ||
| ^ | ||
| Found: (a : ActorRef) | ||
| Required: Unsubscriber.this.bus.Subscriber | ||
| | ||
| Note that I could not resolve reference Unsubscriber.this.bus.Subscriber. | ||
| Subscriber exists as a member of the self type ActorEventBus of trait ManagedActorClassification | ||
| but it cannot be referenced from a scope that does not extend that trait | ||
| | ||
| | ||
| longer explanation available when compiling with `-explain` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
trait ActorRef | ||
|
||
trait ActorEventBus { | ||
type Subscriber = ActorRef | ||
} | ||
|
||
trait ManagedActorClassification { this: ActorEventBus => | ||
def unsubscribe(subscriber: Subscriber): Unit | ||
} | ||
|
||
class Unsubscriber(bus: ManagedActorClassification) { | ||
def test(a: ActorRef): Unit = bus.unsubscribe(a) // error | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,12 @@ | ||
-- Error: tests/neg/i16407.scala:2:2 ----------------------------------------------------------------------------------- | ||
2 | f(g()) // error // error | ||
| ^ | ||
| cannot resolve reference to type (X.this : Y & X).A | ||
| the classfile defining the type might be missing from the classpath | ||
| or the self type of (X.this : Y & X) might not contain all transitive dependencies | ||
| Cannot resolve reference to type (X.this : Y & X).A. | ||
| The classfile defining the type might be missing from the classpath | ||
| or the self type of (X.this : Y & X) might not contain all transitive dependencies. | ||
-- Error: tests/neg/i16407.scala:2:4 ----------------------------------------------------------------------------------- | ||
2 | f(g()) // error // error | ||
| ^ | ||
| cannot resolve reference to type (X.this : Y & X).A | ||
| the classfile defining the type might be missing from the classpath | ||
| or the self type of (X.this : Y & X) might not contain all transitive dependencies | ||
| Cannot resolve reference to type (X.this : Y & X).A. | ||
| The classfile defining the type might be missing from the classpath | ||
| or the self type of (X.this : Y & X) might not contain all transitive dependencies. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
trait A { | ||
class T() | ||
} | ||
trait B { | ||
this: A => | ||
def f(a: Int = 0): Any | ||
} | ||
trait C extends B { | ||
this: A => | ||
def f(t: T): Any | ||
} |