Skip to content

Commit

Permalink
Merge pull request #14461 from dotty-staging/fix-use-of-exported-prefix
Browse files Browse the repository at this point in the history
Fix use of exported prefix
  • Loading branch information
odersky authored Feb 13, 2022
2 parents ddac928 + 64c04d5 commit 679f3d8
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 1 deletion.
6 changes: 5 additions & 1 deletion compiler/src/dotty/tools/dotc/ast/tpd.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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 _ =>
Expand Down
17 changes: 17 additions & 0 deletions tests/pos/i13490.scala
Original file line number Diff line number Diff line change
@@ -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 =>
}
}
}
13 changes: 13 additions & 0 deletions tests/run/i13490.min.scala
Original file line number Diff line number Diff line change
@@ -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")

0 comments on commit 679f3d8

Please sign in to comment.