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

Refine typing of export forwarders #8408

Merged
merged 2 commits into from Mar 1, 2020
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
5 changes: 4 additions & 1 deletion compiler/src/dotty/tools/dotc/typer/Namer.scala
Expand Up @@ -1088,8 +1088,11 @@ class Namer { typer: Typer =>
// allow such type aliases. If we forbid them at some point (requiring the referred type to be
// fully applied), we'd have to change the scheme here as well.
else {
def refersToPrivate(tp: Type): Boolean = tp match
case tp: TermRef => tp.termSymbol.is(Private) || refersToPrivate(tp.prefix)
case _ => false
val (maybeStable, mbrInfo) =
if (sym.isStableMember && sym.isPublic)
if sym.isStableMember && sym.isPublic && !refersToPrivate(path.tpe) then
(StableRealizable, ExprType(path.tpe.select(sym)))
else
(EmptyFlags, mbr.info.ensureMethodic)
Expand Down
4 changes: 3 additions & 1 deletion docs/docs/reference/other-new-features/export.md
Expand Up @@ -77,7 +77,9 @@ Export aliases are always `final`. Aliases of given instances are again defined
not marked `override`.
- However, export aliases can implement deferred members of base classes.

Export aliases for public value definitions are marked by the compiler as "stable" and their result types are the singleton types of the aliased definitions. This means that they can be used as parts of stable identifier paths, even though they are technically methods. For instance, the following is OK:
Export aliases for public value definitions that are accessed without
referring to private values in the qualifier path
are marked by the compiler as "stable" and their result types are the singleton types of the aliased definitions. This means that they can be used as parts of stable identifier paths, even though they are technically methods. For instance, the following is OK:
```scala
class C { type T }
object O { val c: C = ... }
Expand Down
2 changes: 1 addition & 1 deletion tests/neg/exports.check
Expand Up @@ -11,7 +11,7 @@
25 | export printUnit.bitmap // error: no eligible member
| ^
| non-private method bitmap in class Copier refers to private value printUnit
| in its type signature => Copier.this.printUnit.bitmap.type
| in its type signature => Copier.this.printUnit.bitmap$
-- [E120] Duplicate Symbol Error: tests/neg/exports.scala:23:33 --------------------------------------------------------
23 | export printUnit.{stat => _, _} // error: double definition
| ^
Expand Down
10 changes: 9 additions & 1 deletion tests/run/exports.scala
Expand Up @@ -39,9 +39,17 @@ object Test extends App {
1.scanned
}
test()

val _: Int = B.x
}

final class Foo {
lazy val foo : Foo = new Foo
export foo._ // nothing is exported
}
}

class A:
val x: Int = 1
class B(a: A):
export a.x
object B extends B(A())