Skip to content

Commit ea2b10d

Browse files
committed
special case pickling polyfunction
1 parent f7eda3a commit ea2b10d

File tree

4 files changed

+22
-7
lines changed

4 files changed

+22
-7
lines changed

compiler/src/dotty/tools/dotc/core/tasty/TreePickler.scala

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -414,11 +414,19 @@ class TreePickler(pickler: TastyPickler) {
414414
pickleNameAndSig(name, sig, ename)
415415
pickleTree(qual)
416416
else
417+
def isPolyFunction =
418+
val denot = tree.denot
419+
!denot.symbol.exists
420+
&& !denot.isOverloaded
421+
&& denot.infoOrCompleter.isInstanceOf[MethodOrPoly]
422+
&& qual.tpe.classSymbol == defn.PolyFunctionClass
417423
writeByte(SELECTin)
418424
withLength {
419425
pickleNameAndSig(name, tree.symbol.signature, ename)
420426
pickleTree(qual)
421-
if tree.symbol.exists then // TODO: `1.unary_+` has no symbol
427+
if isPolyFunction then
428+
pickleType(defn.PolyFunctionType)
429+
else
422430
pickleType(tree.symbol.owner.typeRef)
423431
}
424432
}

compiler/src/dotty/tools/dotc/core/tasty/TreeUnpickler.scala

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1182,13 +1182,14 @@ class TreeUnpickler(reader: TastyReader,
11821182
var symname = readName()
11831183
val qual = readTerm()
11841184
val qualType = qual.tpe.widenIfUnstable
1185-
val space = if currentAddr == end then qualType else readType()
1185+
val space = readType()
11861186
def select(name: Name, sig: Signature, target: Name) =
11871187
def accessibleDenot(qualType: Type, name: Name, sig: Signature, target: Name) = {
11881188
val pre = ctx.typeAssigner.maybeSkolemizePrefix(qualType, name)
11891189
val d1 = qualType.findMember(name, pre)
1190-
if !d1.isOverloaded && !d1.atSignature(sig, target).symbol.exists then
1191-
// TODO: workaround for refined types
1190+
if !d1.isOverloaded && d1.infoOrCompleter.isInstanceOf[MethodOrPoly] then
1191+
// workaround for method refinements that either override param names,
1192+
// or polymorphic function types
11921193
d1
11931194
else
11941195
val d = space.decl(name).atSignature(sig, target)

compiler/src/dotty/tools/dotc/semanticdb/Scala3.scala

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,8 +114,10 @@ object Scala3:
114114

115115
/** Is symbol global? Non-global symbols get localN names */
116116
def isGlobal(using Context): Boolean =
117-
sym.is(Package)
118-
|| !sym.isSelfSym && (sym.is(Param) || sym.owner.isClass) && sym.owner.isGlobal
117+
sym.exists && (
118+
sym.is(Package)
119+
|| !sym.isSelfSym && (sym.is(Param) || sym.owner.isClass) && sym.owner.isGlobal
120+
)
119121

120122
def isLocalWithinSameName(using Context): Boolean =
121123
sym.exists && !sym.isGlobal && sym.name == sym.owner.name

tests/pos/i8516.scala

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
11
val x: Function1[Int, Int] { def apply(arg: Int): Int } = x => x
22
val x1 = x
3-
val y = x.apply(arg = 1)
3+
val y = x.apply(arg = 1)
4+
5+
val m: [T] => (arg: T) => T = [T] => (arg: T) => arg
6+
val m1 = m
7+
val n = m1(arg = 23)

0 commit comments

Comments
 (0)