Skip to content

Commit 679f3d8

Browse files
authored
Merge pull request #14461 from dotty-staging/fix-use-of-exported-prefix
Fix use of exported prefix
2 parents ddac928 + 64c04d5 commit 679f3d8

File tree

3 files changed

+35
-1
lines changed

3 files changed

+35
-1
lines changed

compiler/src/dotty/tools/dotc/ast/tpd.scala

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1383,7 +1383,11 @@ object tpd extends Trees.Instance[Type] with TypedTreeInfo {
13831383
/** Recover identifier prefix (e.g. this) if it exists */
13841384
def desugarIdentPrefix(tree: Ident)(using Context): Tree = tree.tpe match {
13851385
case TermRef(prefix: TermRef, _) =>
1386-
ref(prefix)
1386+
prefix.info match
1387+
case mt: MethodType if mt.paramInfos.isEmpty && mt.resultType.typeSymbol.is(Module) =>
1388+
ref(mt.resultType.typeSymbol.sourceModule)
1389+
case _ =>
1390+
ref(prefix)
13871391
case TermRef(prefix: ThisType, _) =>
13881392
This(prefix.cls)
13891393
case _ =>

tests/pos/i13490.scala

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
object MyApi {
2+
enum MyEnum(a: Int) {
3+
case A extends MyEnum(1)
4+
}
5+
case class Foo(a: MyEnum)
6+
}
7+
8+
object Test {
9+
export MyApi.*
10+
import MyEnum.*
11+
Foo(MyEnum.A) match {
12+
case Foo(a) =>
13+
a match {
14+
case A =>
15+
}
16+
}
17+
}

tests/run/i13490.min.scala

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
object MyTypes:
2+
enum MyEnum:
3+
case Foo
4+
case Bar
5+
6+
object MyApi:
7+
export MyTypes.*
8+
9+
object MyUse:
10+
import MyApi.MyEnum.Foo
11+
def foo = Foo
12+
13+
@main def Test = assert(MyUse.foo.toString == "Foo")

0 commit comments

Comments
 (0)