Skip to content

Commit 0ddd27d

Browse files
authored
Merge pull request #14681 from dotty-staging/fix-14160
Export constructor proxies for parameterized classes
2 parents 30ce9a5 + 37e9080 commit 0ddd27d

File tree

2 files changed

+29
-4
lines changed

2 files changed

+29
-4
lines changed

compiler/src/dotty/tools/dotc/core/NamerOps.scala

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ package core
44

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

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

76+
/** If this is a reference to a class and the reference has a stable prefix, the reference
77+
* otherwise NoType
78+
*/
79+
private def underlyingStableClassRef(tp: Type)(using Context): TypeRef | NoType.type = tp match
80+
case EtaExpansion(tp1) => underlyingStableClassRef(tp1)
81+
case _ => tp.underlyingClassRef(refinementOK = false) match
82+
case ref: TypeRef if ref.prefix.isStable => ref
83+
case _ => NoType
84+
7585
/** Does symbol `sym` need constructor proxies to be generated? */
7686
def needsConstructorProxies(sym: Symbol)(using Context): Boolean =
7787
sym.isClass
7888
&& !sym.flagsUNSAFE.isOneOf(NoConstructorProxyNeededFlags)
7989
&& !sym.isAnonymousClass
8090
||
8191
sym.isType && sym.is(Exported)
82-
&& sym.info.loBound.underlyingClassRef(refinementOK = false).match
83-
case tref: TypeRef => tref.prefix.isStable
84-
case _ => false
92+
&& underlyingStableClassRef(sym.info.loBound).exists
8593

8694
/** The completer of a constructor proxy apply method */
8795
class ApplyProxyCompleter(constr: Symbol)(using Context) extends LazyType:
@@ -152,7 +160,7 @@ object NamerOps:
152160
then
153161
classConstructorCompanion(mbr).entered
154162
case _ =>
155-
mbr.info.loBound.underlyingClassRef(refinementOK = false) match
163+
underlyingStableClassRef(mbr.info.loBound): @unchecked match
156164
case ref: TypeRef =>
157165
val proxy = ref.symbol.registeredCompanion
158166
if proxy.is(ConstructorProxy) && !memberExists(cls, mbr.name.toTermName) then

tests/pos/i14160.scala

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
object api:
2+
export impl.*
3+
4+
object impl:
5+
class Bar[T](foo: T)
6+
7+
object Test1:
8+
import api.*
9+
val value = Bar(0) // Not Found: Bar
10+
11+
object Test2:
12+
import impl.*
13+
val value = Bar(0) // Works
14+
15+
object Test3:
16+
import api.*
17+
val value = new Bar[Int](0) // Works

0 commit comments

Comments
 (0)