Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix use of exported prefix #14461

Merged
merged 2 commits into from Feb 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 5 additions & 1 deletion compiler/src/dotty/tools/dotc/ast/tpd.scala
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
@@ -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
@@ -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")