Skip to content

Commit eda3bcb

Browse files
committed
Include mixins when checking for cyclic exports
1 parent 6ede8f1 commit eda3bcb

File tree

4 files changed

+25
-7
lines changed

4 files changed

+25
-7
lines changed

compiler/src/dotty/tools/dotc/typer/Namer.scala

+4-4
Original file line numberDiff line numberDiff line change
@@ -1179,11 +1179,11 @@ class Namer { typer: Typer =>
11791179
* The export selects a member of the current class (issue #22147).
11801180
* Assumes that cls.classInfo.selfType.derivesFrom(sym.owner) is true.
11811181
*/
1182-
def isCurrentMember: Boolean = expr match
1182+
def isCurrentClassMember: Boolean = expr match
11831183
case id: (Ident | This) => // Access through self type or this
11841184
/* Given the usage context below, where cls's self type is a subtype of sym.owner,
1185-
it suffices to check if the denotation is a ClassInfo */
1186-
id.denot.info.isInstanceOf[ClassInfo]
1185+
it suffices to check if symbol is the same class. */
1186+
cls == id.symbol
11871187
case _ => false
11881188
if !sym.isAccessibleFrom(pathType) then
11891189
No("is not accessible")
@@ -1194,7 +1194,7 @@ class Namer { typer: Typer =>
11941194
// * the symbols owner is the cls itself
11951195
// * the symbol is not a deferred symbol
11961196
// * the symbol is a member of the current class (#22147)
1197-
else if cls.classInfo.selfType.derivesFrom(sym.owner) && (sym.owner == cls || !sym.is(Deferred) || isCurrentMember) then
1197+
else if cls.classInfo.selfType.derivesFrom(sym.owner) && (sym.owner == cls || !sym.is(Deferred) || isCurrentClassMember) then
11981198
No(i"is already a member of $cls")
11991199
else if pathMethod.exists && mbr.isType then
12001200
No("is a type, so it cannot be exported as extension method")

tests/neg/exports3.scala

+6-2
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ trait R extends P:
1212
val a1: A
1313
val a2: A
1414

15-
class B extends R:
15+
abstract class B extends R:
1616
self =>
1717
export this.baz // error
1818
export self.bar // error
@@ -34,4 +34,8 @@ abstract class F:
3434

3535
class G(p: P):
3636
self: P =>
37-
export p.foo
37+
export p.foo
38+
39+
class H(p: P):
40+
self: P =>
41+
export this.p.foo

tests/neg/i20245.check

+14
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,17 @@
1515
| Run with both -explain-cyclic and -Ydebug-cyclic to see full stack trace.
1616
|
1717
| longer explanation available when compiling with `-explain`
18+
-- [E046] Cyclic Error: tests/neg/i20245/Typer_2.scala:10:7 ------------------------------------------------------------
19+
10 |import effekt.source.{ resolve } // error
20+
| ^
21+
| Cyclic reference involving class Context
22+
|
23+
| The error occurred while trying to compute the base classes of class Context
24+
| which required to compute the base classes of trait TyperOps
25+
| which required to compute the signature of trait TyperOps
26+
| which required to elaborate the export clause export unification.requireSubtype
27+
| which required to compute the base classes of class Context
28+
|
29+
| Run with both -explain-cyclic and -Ydebug-cyclic to see full stack trace.
30+
|
31+
| longer explanation available when compiling with `-explain`

tests/neg/i20245/Typer_2.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import effekt.util.messages.ErrorReporter
77
import effekt.context.{ Context }
88

99
// This import is also NECESSARY for the cyclic error
10-
import effekt.source.{ resolve }
10+
import effekt.source.{ resolve } // error
1111

1212

1313
trait TyperOps extends ErrorReporter { self: Context =>

0 commit comments

Comments
 (0)