diff --git a/compiler/src/dotty/tools/dotc/ast/tpd.scala b/compiler/src/dotty/tools/dotc/ast/tpd.scala index 98ea6e0c5c44..396d85a8c58a 100644 --- a/compiler/src/dotty/tools/dotc/ast/tpd.scala +++ b/compiler/src/dotty/tools/dotc/ast/tpd.scala @@ -1383,7 +1383,11 @@ object tpd extends Trees.Instance[Type] with TypedTreeInfo { /** Recover identifier prefix (e.g. this) if it exists */ def desugarIdentPrefix(tree: Ident)(using Context): Tree = tree.tpe match { case TermRef(prefix: TermRef, _) => - ref(prefix) + prefix.info match + case mt: MethodType if mt.paramInfos.isEmpty && mt.resultType.typeSymbol.is(Module) => + ref(mt.resultType.typeSymbol.sourceModule) + case _ => + ref(prefix) case TermRef(prefix: ThisType, _) => This(prefix.cls) case _ => diff --git a/tests/pos/i13490.scala b/tests/pos/i13490.scala new file mode 100644 index 000000000000..c8f3213e0649 --- /dev/null +++ b/tests/pos/i13490.scala @@ -0,0 +1,17 @@ +object MyApi { + enum MyEnum(a: Int) { + case A extends MyEnum(1) + } + case class Foo(a: MyEnum) +} + +object Test { + export MyApi.* + import MyEnum.* + Foo(MyEnum.A) match { + case Foo(a) => + a match { + case A => + } + } +} diff --git a/tests/run/i13490.min.scala b/tests/run/i13490.min.scala new file mode 100644 index 000000000000..4f9c19764a5d --- /dev/null +++ b/tests/run/i13490.min.scala @@ -0,0 +1,13 @@ +object MyTypes: + enum MyEnum: + case Foo + case Bar + +object MyApi: + export MyTypes.* + +object MyUse: + import MyApi.MyEnum.Foo + def foo = Foo + +@main def Test = assert(MyUse.foo.toString == "Foo")