Skip to content

Export constructor proxies for parameterized classes #14681

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

Merged
merged 1 commit into from
Mar 14, 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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions compiler/src/dotty/tools/dotc/core/NamerOps.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ package core

import Contexts._, Symbols._, Types._, Flags._, Scopes._, Decorators._, Names._, NameOps._
import SymDenotations.{LazyType, SymDenotation}, StdNames.nme
import TypeApplications.EtaExpansion

/** Operations that are shared between Namer and TreeUnpickler */
object NamerOps:
Expand Down Expand Up @@ -72,16 +73,23 @@ object NamerOps:
/** The flags of an `apply` method that serves as a constructor proxy */
val ApplyProxyFlags = Synthetic | ConstructorProxy | Inline | Method

/** If this is a reference to a class and the reference has a stable prefix, the reference
* otherwise NoType
*/
private def underlyingStableClassRef(tp: Type)(using Context): TypeRef | NoType.type = tp match
case EtaExpansion(tp1) => underlyingStableClassRef(tp1)
case _ => tp.underlyingClassRef(refinementOK = false) match
case ref: TypeRef if ref.prefix.isStable => ref
case _ => NoType

/** Does symbol `sym` need constructor proxies to be generated? */
def needsConstructorProxies(sym: Symbol)(using Context): Boolean =
sym.isClass
&& !sym.flagsUNSAFE.isOneOf(NoConstructorProxyNeededFlags)
&& !sym.isAnonymousClass
||
sym.isType && sym.is(Exported)
&& sym.info.loBound.underlyingClassRef(refinementOK = false).match
case tref: TypeRef => tref.prefix.isStable
case _ => false
&& underlyingStableClassRef(sym.info.loBound).exists

/** The completer of a constructor proxy apply method */
class ApplyProxyCompleter(constr: Symbol)(using Context) extends LazyType:
Expand Down Expand Up @@ -152,7 +160,7 @@ object NamerOps:
then
classConstructorCompanion(mbr).entered
case _ =>
mbr.info.loBound.underlyingClassRef(refinementOK = false) match
underlyingStableClassRef(mbr.info.loBound): @unchecked match
case ref: TypeRef =>
val proxy = ref.symbol.registeredCompanion
if proxy.is(ConstructorProxy) && !memberExists(cls, mbr.name.toTermName) then
Expand Down
17 changes: 17 additions & 0 deletions tests/pos/i14160.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
object api:
export impl.*

object impl:
class Bar[T](foo: T)

object Test1:
import api.*
val value = Bar(0) // Not Found: Bar

object Test2:
import impl.*
val value = Bar(0) // Works

object Test3:
import api.*
val value = new Bar[Int](0) // Works