Skip to content

Commit f918a6c

Browse files
authored
Merge pull request #3621 from dotty-staging/fix-#3608
Fix #3608: Treat outer selections as separate Tasty tree
2 parents 0f494ea + dd0e68e commit f918a6c

File tree

6 files changed

+51
-24
lines changed

6 files changed

+51
-24
lines changed

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ object NameTags extends TastyFormat.NameTags {
1111

1212
final val TRAITSETTER = 6 // A Scala-2 trait setter, generated by AugmentScala2Traits
1313

14+
final val OUTERSELECT = 13 // A name `<num>_outer`, used by the inliner to indicate an
15+
// outer accessor that will be filled in by ExplicitOuter.
16+
// <num> indicates the number of hops needed to select the outer field.
17+
1418
final val INITIALIZER = 24 // A mixin initializer method
1519

1620
final val AVOIDCLASH = 25 // Adds a suffix to avoid a name clash;

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

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,11 @@ Macro-format:
3737
UNIQUE Length separator_NameRef uniqid_Nat underlying_NameRef?
3838
DEFAULTGETTER Length underlying_NameRef index_Nat
3939
VARIANT Length underlying_NameRef variance_Nat // 0: Contravariant, 1: Covariant
40-
OUTERSELECT Length underlying_NameRef nhops_Nat
4140
4241
SUPERACCESSOR Length underlying_NameRef
4342
PROTECTEDACCESSOR Length underlying_NameRef
4443
PROTECTEDSETTER Length underlying_NameRef
45-
INITIALIZER Length underlying_NameRef
44+
OBJECTCLASS Length underlying_NameRef
4645
4746
SIGNED Length original_NameRef resultSig_NameRef paramSig_NameRef*
4847
@@ -81,9 +80,9 @@ Standard-Section: "ASTs" TopLevelStat*
8180
SELECT possiblySigned_NameRef qual_Term
8281
QUALTHIS typeIdent_Tree
8382
NEW cls_Type
83+
NAMEDARG paramName_NameRef arg_Term
8484
SUPER Length this_Term mixinTypeIdent_Tree?
8585
TYPED Length expr_Term ascription_Type
86-
NAMEDARG Length paramName_NameRef arg_Term
8786
ASSIGN Length lhs_Term rhs_Term
8887
BLOCK Length expr_Term Stat*
8988
INLINED Length call_Term expr_Term Stat*
@@ -93,6 +92,7 @@ Standard-Section: "ASTs" TopLevelStat*
9392
TRY Length expr_Term CaseDef* finalizer_Term?
9493
RETURN Length meth_ASTRef expr_Term?
9594
REPEATED Length elem_Type elem_Term*
95+
SELECTouter Length levels_Nat qual_Term underlying_Type
9696
BIND Length boundName_NameRef patType_Type pat_Term
9797
ALTERNATIVE Length alt_Term*
9898
UNAPPLY Length fun_Term ImplicitArg* pat_Type pat_Term*
@@ -248,10 +248,6 @@ object TastyFormat {
248248
final val VARIANT = 12 // A name `+<name>` o `-<name>` indicating
249249
// a co- or contra-variant parameter of a type lambda.
250250

251-
final val OUTERSELECT = 13 // A name `<num>_outer`, used by the inliner to indicate an
252-
// outer accessor that will be filled in by ExplicitOuter.
253-
// <num> indicates the number of hops needed to select the outer field.
254-
255251
final val SUPERACCESSOR = 20 // The name of a super accessor `super$name` created by SuperAccesors.
256252

257253
final val PROTECTEDACCESSOR = 21 // The name of a protected accessor `protected$<name>` created by SuperAccesors.
@@ -336,6 +332,7 @@ object TastyFormat {
336332
final val RECtype = 90
337333
final val TYPEALIAS = 91
338334
final val SINGLETONtpt = 92
335+
final val NAMEDARG = 93
339336

340337
// Cat. 4: tag Nat AST
341338

@@ -362,15 +359,15 @@ object TastyFormat {
362359
final val APPLY = 136
363360
final val TYPEAPPLY = 137
364361
final val TYPED = 138
365-
final val NAMEDARG = 139
366-
final val ASSIGN = 140
367-
final val BLOCK = 141
368-
final val IF = 142
369-
final val LAMBDA = 143
370-
final val MATCH = 144
371-
final val RETURN = 145
372-
final val TRY = 146
373-
final val INLINED = 147
362+
final val ASSIGN = 139
363+
final val BLOCK = 140
364+
final val IF = 141
365+
final val LAMBDA = 142
366+
final val MATCH = 143
367+
final val RETURN = 144
368+
final val TRY = 145
369+
final val INLINED = 146
370+
final val SELECTouter = 147
374371
final val REPEATED = 148
375372
final val BIND = 149
376373
final val ALTERNATIVE = 150
@@ -536,6 +533,7 @@ object TastyFormat {
536533
case MATCH => "MATCH"
537534
case RETURN => "RETURN"
538535
case INLINED => "INLINED"
536+
case SELECTouter => "SELECTouter"
539537
case TRY => "TRY"
540538
case REPEATED => "REPEATED"
541539
case BIND => "BIND"

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ class TastyUnpickler(reader: TastyReader) {
5858
val originals = until(end)(readName())
5959
val original = if (originals.isEmpty) EmptyTermName else originals.head
6060
uniqueNameKindOfSeparator(separator)(original, num)
61-
case DEFAULTGETTER | VARIANT | OUTERSELECT =>
61+
case DEFAULTGETTER | VARIANT =>
6262
numberedNameKindOfTag(tag)(readName(), readNat())
6363
case SIGNED =>
6464
val original = readName()

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

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -342,10 +342,21 @@ class TreePickler(pickler: TastyPickler) {
342342
pickleTree(qual.withType(tref))
343343
}
344344
case Select(qual, name) =>
345-
writeByte(if (name.isTypeName) SELECTtpt else SELECT)
346-
val sig = tree.tpe.signature
347-
pickleNameAndSig(name, sig)
348-
pickleTree(qual)
345+
name match {
346+
case OuterSelectName(_, levels) =>
347+
writeByte(SELECTouter)
348+
withLength {
349+
writeNat(levels)
350+
pickleTree(qual)
351+
val SkolemType(tp) = tree.tpe
352+
pickleType(tp)
353+
}
354+
case _ =>
355+
writeByte(if (name.isTypeName) SELECTtpt else SELECT)
356+
val sig = tree.tpe.signature
357+
pickleNameAndSig(name, sig)
358+
pickleTree(qual)
359+
}
349360
case Apply(fun, args) =>
350361
writeByte(APPLY)
351362
withLength {
@@ -382,7 +393,8 @@ class TreePickler(pickler: TastyPickler) {
382393
withLength { pickleTree(expr); pickleTpt(tpt) }
383394
case NamedArg(name, arg) =>
384395
writeByte(NAMEDARG)
385-
withLength { pickleName(name); pickleTree(arg) }
396+
pickleName(name)
397+
pickleTree(arg)
386398
case Assign(lhs, rhs) =>
387399
writeByte(ASSIGN)
388400
withLength { pickleTree(lhs); pickleTree(rhs) }

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -913,6 +913,8 @@ class TreeUnpickler(reader: TastyReader, nameAtRef: NameRef => TermName, posUnpi
913913
SingletonTypeTree(readTerm())
914914
case BYNAMEtpt =>
915915
ByNameTypeTree(readTpt())
916+
case NAMEDARG =>
917+
NamedArg(readName(), readTerm())
916918
case _ =>
917919
readPathTerm()
918920
}
@@ -960,8 +962,6 @@ class TreeUnpickler(reader: TastyReader, nameAtRef: NameRef => TermName, posUnpi
960962
case expr => expr
961963
}
962964
Typed(expr1, tpt)
963-
case NAMEDARG =>
964-
NamedArg(readName(), readTerm())
965965
case ASSIGN =>
966966
Assign(readTerm(), readTerm())
967967
case BLOCK =>
@@ -983,6 +983,9 @@ class TreeUnpickler(reader: TastyReader, nameAtRef: NameRef => TermName, posUnpi
983983
Return(expr, Ident(from.termRef))
984984
case TRY =>
985985
Try(readTerm(), readCases(end), ifBefore(end)(readTerm(), EmptyTree))
986+
case SELECTouter =>
987+
val levels = readNat()
988+
readTerm().outerSelect(levels, SkolemType(readType()))
986989
case REPEATED =>
987990
val elemtpt = readTpt()
988991
SeqLiteral(until(end)(readTerm()), elemtpt)

tests/pickling/i3608.scala

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
class A {
2+
class Foo {
3+
inline def inlineMeth: Unit = new Bar
4+
}
5+
class Bar
6+
}
7+
8+
class B extends A {
9+
(new Foo).inlineMeth
10+
}

0 commit comments

Comments
 (0)