Skip to content

Commit 1d7208a

Browse files
committed
Workaround scala 2.12 Eta expansion warning
This should be reverted in the future.
1 parent 8a78f92 commit 1d7208a

File tree

7 files changed

+68
-68
lines changed

7 files changed

+68
-68
lines changed

compiler/src/dotty/tools/dotc/core/unpickleScala2/Scala2Unpickler.scala

Lines changed: 43 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -425,7 +425,7 @@ class Scala2Unpickler(bytes: Array[Byte], classRoot: ClassDenotation, moduleClas
425425

426426
// symbols that were pickled with Pickler.writeSymInfo
427427
val nameref = readNat()
428-
var name = at(nameref, readName)
428+
var name = at(nameref, () => readName()(ctx))
429429
val owner = readSymbolRef()
430430

431431
var flags = unpickleScalaFlags(readLongNat(), name.isTypeName)
@@ -543,12 +543,12 @@ class Scala2Unpickler(bytes: Array[Byte], classRoot: ClassDenotation, moduleClas
543543
denot.privateWithin =
544544
if (!isSymbolRef(inforef)) NoSymbol
545545
else {
546-
val pw = at(inforef, readSymbol)
546+
val pw = at(inforef, () => readSymbol())
547547
inforef = readNat()
548548
pw
549549
}
550550
// println("reading type for " + denot) // !!! DEBUG
551-
val tp = at(inforef, readType)
551+
val tp = at(inforef, () => readType()(ctx))
552552
denot match {
553553
case denot: ClassDenotation =>
554554
val selfInfo = if (atEnd) NoType else readTypeRef()
@@ -599,11 +599,11 @@ class Scala2Unpickler(bytes: Array[Byte], classRoot: ClassDenotation, moduleClas
599599
val end = readNat() + readIndex
600600
if (tag == POLYtpe) {
601601
val unusedRestpeRef = readNat()
602-
until(end, readSymbolRef).asInstanceOf[List[TypeSymbol]]
602+
until(end, () => readSymbolRef()(ctx)).asInstanceOf[List[TypeSymbol]]
603603
} else Nil
604604
}
605605
private def loadTypeParams(implicit ctx: Context) =
606-
atReadPos(index(infoRef), readTypeParams)
606+
atReadPos(index(infoRef), () => readTypeParams()(ctx))
607607

608608
/** Force reading type params early, we need them in setClassInfo of subclasses. */
609609
def init()(implicit ctx: Context) = loadTypeParams
@@ -741,7 +741,7 @@ class Scala2Unpickler(bytes: Array[Byte], classRoot: ClassDenotation, moduleClas
741741
}
742742
else
743743
TypeRef(pre, sym.name.asTypeName)
744-
val args = until(end, readTypeRef)
744+
val args = until(end, () => readTypeRef())
745745
if (sym == defn.ByNameParamClass2x) ExprType(args.head)
746746
else if (args.nonEmpty) tycon.safeAppliedTo(EtaExpandIfHK(sym.typeParams, args.map(translateTempPoly)))
747747
else if (sym.typeParams.nonEmpty) tycon.EtaExpand(sym.typeParams)
@@ -752,7 +752,7 @@ class Scala2Unpickler(bytes: Array[Byte], classRoot: ClassDenotation, moduleClas
752752
val clazz = readSymbolRef()
753753
val decls = symScope(clazz)
754754
symScopes(clazz) = EmptyScope // prevent further additions
755-
val parents = until(end, readTypeRef)
755+
val parents = until(end, () => readTypeRef())
756756
val parent = parents.reduceLeft(AndType(_, _))
757757
if (decls.isEmpty) parent
758758
else {
@@ -765,26 +765,26 @@ class Scala2Unpickler(bytes: Array[Byte], classRoot: ClassDenotation, moduleClas
765765
}
766766
case CLASSINFOtpe =>
767767
val clazz = readSymbolRef()
768-
TempClassInfoType(until(end, readTypeRef), symScope(clazz), clazz)
768+
TempClassInfoType(until(end, () => readTypeRef()), symScope(clazz), clazz)
769769
case METHODtpe | IMPLICITMETHODtpe =>
770770
val restpe = readTypeRef()
771-
val params = until(end, readSymbolRef).asInstanceOf[List[TermSymbol]]
771+
val params = until(end, () => readSymbolRef()).asInstanceOf[List[TermSymbol]]
772772
def isImplicit =
773773
tag == IMPLICITMETHODtpe ||
774774
params.nonEmpty && (params.head is Implicit)
775775
val maker = if (isImplicit) ImplicitMethodType else MethodType
776776
maker.fromSymbols(params, restpe)
777777
case POLYtpe =>
778778
val restpe = readTypeRef()
779-
val typeParams = until(end, readSymbolRef)
779+
val typeParams = until(end, () => readSymbolRef())
780780
if (typeParams.nonEmpty) TempPolyType(typeParams.asInstanceOf[List[TypeSymbol]], restpe.widenExpr)
781781
else ExprType(restpe)
782782
case EXISTENTIALtpe =>
783783
val restpe = readTypeRef()
784-
val boundSyms = until(end, readSymbolRef)
784+
val boundSyms = until(end, () => readSymbolRef())
785785
elimExistentials(boundSyms, restpe)
786786
case ANNOTATEDtpe =>
787-
AnnotatedType.make(readTypeRef(), until(end, readAnnotationRef))
787+
AnnotatedType.make(readTypeRef(), until(end, () => readAnnotationRef()))
788788
case _ =>
789789
noSuchTypeTag(tag, end)
790790
}
@@ -795,7 +795,7 @@ class Scala2Unpickler(bytes: Array[Byte], classRoot: ClassDenotation, moduleClas
795795
val end = readNat() + readIndex
796796
if (tag == POLYtpe) {
797797
val unusedRestperef = readNat()
798-
until(end, readSymbolRef)
798+
until(end, () => readSymbolRef())
799799
} else Nil
800800
}
801801

@@ -859,26 +859,26 @@ class Scala2Unpickler(bytes: Array[Byte], classRoot: ClassDenotation, moduleClas
859859
}
860860

861861
protected def readDisambiguatedSymbolRef(p: Symbol => Boolean)(implicit ctx: Context): Symbol =
862-
at(readNat(), readDisambiguatedSymbol(p))
862+
at(readNat(), () => readDisambiguatedSymbol(p)())
863863

864-
protected def readNameRef()(implicit ctx: Context): Name = at(readNat(), readName)
864+
protected def readNameRef()(implicit ctx: Context): Name = at(readNat(), () => readName())
865865
protected def readTypeRef()(implicit ctx: Context): Type = at(readNat(), () => readType()) // after the NMT_TRANSITION period, we can leave off the () => ... ()
866-
protected def readConstantRef()(implicit ctx: Context): Constant = at(readNat(), readConstant)
866+
protected def readConstantRef()(implicit ctx: Context): Constant = at(readNat(), () => readConstant())
867867

868868
protected def readTypeNameRef()(implicit ctx: Context): TypeName = readNameRef().toTypeName
869869
protected def readTermNameRef()(implicit ctx: Context): TermName = readNameRef().toTermName
870870

871-
protected def readAnnotationRef()(implicit ctx: Context): Annotation = at(readNat(), readAnnotation)
871+
protected def readAnnotationRef()(implicit ctx: Context): Annotation = at(readNat(), () => readAnnotation())
872872

873873
protected def readModifiersRef(isType: Boolean)(implicit ctx: Context): Modifiers = at(readNat(), () => readModifiers(isType))
874-
protected def readTreeRef()(implicit ctx: Context): Tree = at(readNat(), readTree)
874+
protected def readTreeRef()(implicit ctx: Context): Tree = at(readNat(), () => readTree())
875875

876876
/** Read an annotation argument, which is pickled either
877877
* as a Constant or a Tree.
878878
*/
879879
protected def readAnnotArg(i: Int)(implicit ctx: Context): Tree = bytes(index(i)) match {
880-
case TREE => at(i, readTree)
881-
case _ => Literal(at(i, readConstant))
880+
case TREE => at(i, () => readTree())
881+
case _ => Literal(at(i, () => readConstant()))
882882
}
883883

884884
/** Read a ClassfileAnnotArg (argument to a classfile annotation)
@@ -899,8 +899,8 @@ class Scala2Unpickler(bytes: Array[Byte], classRoot: ClassDenotation, moduleClas
899899
}
900900

901901
protected def readClassfileAnnotArg(i: Int)(implicit ctx: Context): Tree = bytes(index(i)) match {
902-
case ANNOTINFO => at(i, readAnnotInfoArg)
903-
case ANNOTARGARRAY => at(i, readArrayAnnotArg)
902+
case ANNOTINFO => at(i, () => readAnnotInfoArg())
903+
case ANNOTARGARRAY => at(i, () => readArrayAnnotArg())
904904
case _ => readAnnotArg(i)
905905
}
906906

@@ -916,7 +916,7 @@ class Scala2Unpickler(bytes: Array[Byte], classRoot: ClassDenotation, moduleClas
916916
val argref = readNat()
917917
t += {
918918
if (isNameEntry(argref)) {
919-
val name = at(argref, readName)
919+
val name = at(argref, () => readName())
920920
val arg = readClassfileAnnotArg(readNat())
921921
NamedArg(name.asTermName, arg)
922922
} else readAnnotArg(argref)
@@ -1007,13 +1007,13 @@ class Scala2Unpickler(bytes: Array[Byte], classRoot: ClassDenotation, moduleClas
10071007
case PACKAGEtree =>
10081008
setSym()
10091009
val pid = readTreeRef().asInstanceOf[RefTree]
1010-
val stats = until(end, readTreeRef)
1010+
val stats = until(end, () => readTreeRef())
10111011
PackageDef(pid, stats)
10121012

10131013
case CLASStree =>
10141014
setSymModsName()
10151015
val impl = readTemplateRef()
1016-
val tparams = until(end, readTypeDefRef)
1016+
val tparams = until(end, () => readTypeDefRef())
10171017
val cls = symbol.asClass
10181018
val ((constr: DefDef) :: Nil, stats) =
10191019
impl.body.partition(_.symbol == cls.primaryConstructor)
@@ -1031,22 +1031,22 @@ class Scala2Unpickler(bytes: Array[Byte], classRoot: ClassDenotation, moduleClas
10311031

10321032
case DEFDEFtree =>
10331033
setSymModsName()
1034-
val tparams = times(readNat(), readTypeDefRef)
1035-
val vparamss = times(readNat(), () => times(readNat(), readValDefRef))
1034+
val tparams = times(readNat(), () => readTypeDefRef())
1035+
val vparamss = times(readNat(), () => times(readNat(), () => readValDefRef()))
10361036
val tpt = readTreeRef()
10371037
val rhs = readTreeRef()
10381038
DefDef(symbol.asTerm, rhs)
10391039

10401040
case TYPEDEFtree =>
10411041
setSymModsName()
10421042
val rhs = readTreeRef()
1043-
val tparams = until(end, readTypeDefRef)
1043+
val tparams = until(end, () => readTypeDefRef())
10441044
TypeDef(symbol.asType)
10451045

10461046
case LABELtree =>
10471047
setSymName()
10481048
val rhs = readTreeRef()
1049-
val params = until(end, readIdentRef)
1049+
val params = until(end, () => readIdentRef())
10501050
val ldef = DefDef(symbol.asTerm, rhs)
10511051
def isCaseLabel(sym: Symbol) = sym.name.startsWith(nme.CASEkw.toString)
10521052
if (isCaseLabel(symbol)) ldef
@@ -1067,15 +1067,15 @@ class Scala2Unpickler(bytes: Array[Byte], classRoot: ClassDenotation, moduleClas
10671067

10681068
case TEMPLATEtree =>
10691069
setSym()
1070-
val parents = times(readNat(), readTreeRef)
1070+
val parents = times(readNat(), () => readTreeRef())
10711071
val self = readValDefRef()
1072-
val body = until(end, readTreeRef)
1072+
val body = until(end, () => readTreeRef())
10731073
untpd.Template(???, parents, self, body) // !!! TODO: pull out primary constructor
10741074
.withType(symbol.namedType)
10751075

10761076
case BLOCKtree =>
10771077
val expr = readTreeRef()
1078-
val stats = until(end, readTreeRef)
1078+
val stats = until(end, () => readTreeRef())
10791079
Block(stats, expr)
10801080

10811081
case CASEtree =>
@@ -1085,7 +1085,7 @@ class Scala2Unpickler(bytes: Array[Byte], classRoot: ClassDenotation, moduleClas
10851085
CaseDef(pat, guard, body)
10861086

10871087
case ALTERNATIVEtree =>
1088-
Alternative(until(end, readTreeRef))
1088+
Alternative(until(end, () => readTreeRef()))
10891089

10901090
case STARtree =>
10911091
readTreeRef()
@@ -1097,19 +1097,19 @@ class Scala2Unpickler(bytes: Array[Byte], classRoot: ClassDenotation, moduleClas
10971097

10981098
case UNAPPLYtree =>
10991099
val fun = readTreeRef()
1100-
val args = until(end, readTreeRef)
1100+
val args = until(end, () => readTreeRef())
11011101
UnApply(fun, Nil, args, defn.AnyType) // !!! this is wrong in general
11021102

11031103
case ARRAYVALUEtree =>
11041104
val elemtpt = readTreeRef()
1105-
val trees = until(end, readTreeRef)
1105+
val trees = until(end, () => readTreeRef())
11061106
SeqLiteral(trees, elemtpt)
11071107
// note can't deal with trees passed to Java methods as arrays here
11081108

11091109
case FUNCTIONtree =>
11101110
setSym()
11111111
val body = readTreeRef()
1112-
val vparams = until(end, readValDefRef)
1112+
val vparams = until(end, () => readValDefRef())
11131113
val applyType = MethodType(vparams map (_.name), vparams map (_.tpt.tpe), body.tpe)
11141114
val applyMeth = ctx.newSymbol(symbol.owner, nme.apply, Method, applyType)
11151115
Closure(applyMeth, Function.const(body.changeOwner(symbol, applyMeth)) _)
@@ -1127,7 +1127,7 @@ class Scala2Unpickler(bytes: Array[Byte], classRoot: ClassDenotation, moduleClas
11271127

11281128
case MATCHtree =>
11291129
val selector = readTreeRef()
1130-
val cases = until(end, readCaseDefRef)
1130+
val cases = until(end, () => readCaseDefRef())
11311131
Match(selector, cases)
11321132

11331133
case RETURNtree =>
@@ -1137,7 +1137,7 @@ class Scala2Unpickler(bytes: Array[Byte], classRoot: ClassDenotation, moduleClas
11371137
case TREtree =>
11381138
val block = readTreeRef()
11391139
val finalizer = readTreeRef()
1140-
val catches = until(end, readCaseDefRef)
1140+
val catches = until(end, () => readCaseDefRef())
11411141
Try(block, catches, finalizer)
11421142

11431143
case THROWtree =>
@@ -1153,12 +1153,12 @@ class Scala2Unpickler(bytes: Array[Byte], classRoot: ClassDenotation, moduleClas
11531153

11541154
case TYPEAPPLYtree =>
11551155
val fun = readTreeRef()
1156-
val args = until(end, readTreeRef)
1156+
val args = until(end, () => readTreeRef())
11571157
TypeApply(fun, args)
11581158

11591159
case APPLYtree =>
11601160
val fun = readTreeRef()
1161-
val args = until(end, readTreeRef)
1161+
val args = until(end, () => readTreeRef())
11621162
/*
11631163
if (fun.symbol.isOverloaded) {
11641164
fun.setType(fun.symbol.info)
@@ -1170,7 +1170,7 @@ class Scala2Unpickler(bytes: Array[Byte], classRoot: ClassDenotation, moduleClas
11701170
case APPLYDYNAMICtree =>
11711171
setSym()
11721172
val qual = readTreeRef()
1173-
val args = until(end, readTreeRef)
1173+
val args = until(end, () => readTreeRef())
11741174
unimplementedTree("APPLYDYNAMIC")
11751175

11761176
case SUPERtree =>
@@ -1218,7 +1218,7 @@ class Scala2Unpickler(bytes: Array[Byte], classRoot: ClassDenotation, moduleClas
12181218

12191219
case APPLIEDTYPEtree =>
12201220
val tpt = readTreeRef()
1221-
val args = until(end, readTreeRef)
1221+
val args = until(end, () => readTreeRef())
12221222
AppliedTypeTree(tpt, args)
12231223

12241224
case TYPEBOUNDStree =>
@@ -1228,7 +1228,7 @@ class Scala2Unpickler(bytes: Array[Byte], classRoot: ClassDenotation, moduleClas
12281228

12291229
case EXISTENTIALTYPEtree =>
12301230
val tpt = readTreeRef()
1231-
val whereClauses = until(end, readTreeRef)
1231+
val whereClauses = until(end, () => readTreeRef())
12321232
TypeTree(tpe)
12331233

12341234
case _ =>

compiler/src/dotty/tools/dotc/parsing/JavaParsers.scala

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,7 @@ object JavaParsers {
323323
if (in.token == LT) {
324324
in.nextToken()
325325
val t1 = convertToTypeId(t)
326-
val args = repsep(typeArg, COMMA)
326+
val args = repsep(() => typeArg(), COMMA)
327327
acceptClosingAngle()
328328
atPos(t1.pos.start) {
329329
AppliedTypeTree(t1, args)
@@ -435,7 +435,7 @@ object JavaParsers {
435435

436436
def formalParams(): List[ValDef] = {
437437
accept(LPAREN)
438-
val vparams = if (in.token == RPAREN) List() else repsep(formalParam, COMMA)
438+
val vparams = if (in.token == RPAREN) List() else repsep(() => formalParam(), COMMA)
439439
accept(RPAREN)
440440
vparams
441441
}
@@ -459,7 +459,7 @@ object JavaParsers {
459459
def optThrows(): Unit = {
460460
if (in.token == THROWS) {
461461
in.nextToken()
462-
repsep(typ, COMMA)
462+
repsep(() => typ(), COMMA)
463463
}
464464
}
465465

@@ -675,7 +675,7 @@ object JavaParsers {
675675
def interfacesOpt() =
676676
if (in.token == IMPLEMENTS) {
677677
in.nextToken()
678-
repsep(typ, COMMA)
678+
repsep(() => typ(), COMMA)
679679
} else {
680680
List()
681681
}
@@ -708,7 +708,7 @@ object JavaParsers {
708708
val parents =
709709
if (in.token == EXTENDS) {
710710
in.nextToken()
711-
repsep(typ, COMMA)
711+
repsep(() => typ(), COMMA)
712712
} else {
713713
List(javaLangObject())
714714
}

compiler/src/dotty/tools/dotc/parsing/MarkupParserCommon.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ private[dotty] trait MarkupParserCommon {
159159
Utility.parseCharRef(() => c, () => { c = it.next() }, reportSyntaxError _, truncatedError _)
160160
}
161161

162-
def xCharRef: String = xCharRef(() => ch, nextch)
162+
def xCharRef: String = xCharRef(() => ch, () => nextch())
163163

164164
/** Create a lookahead reader which does not influence the input */
165165
def lookahead(): BufferedIterator[Char]

compiler/src/dotty/tools/dotc/parsing/Parsers.scala

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -902,9 +902,9 @@ object Parsers {
902902
in.nextToken()
903903
otherArgs(NamedArg(name, typ()), namedTypeArg)
904904
case firstArg =>
905-
otherArgs(firstArg, typ)
905+
otherArgs(firstArg, () => typ())
906906
}
907-
else commaSeparated(typParser)
907+
else commaSeparated(() => typParser())
908908
}
909909

910910
/** FunArgType ::= Type | `=>' Type
@@ -1825,7 +1825,7 @@ object Parsers {
18251825
TypeDef(name, lambdaAbstract(hkparams, bounds)).withMods(mods)
18261826
}
18271827
}
1828-
commaSeparated(typeParam)
1828+
commaSeparated(() => typeParam())
18291829
}
18301830

18311831
def typeParamClauseOpt(ownerKind: ParamOwner.Value): List[TypeDef] =
@@ -1898,7 +1898,7 @@ object Parsers {
18981898
implicitOffset = in.offset
18991899
imods = implicitMods()
19001900
}
1901-
commaSeparated(param)
1901+
commaSeparated(() => param())
19021902
}
19031903
}
19041904
def clauses(): List[List[ValDef]] = {
@@ -2283,7 +2283,7 @@ object Parsers {
22832283
classDefRest(start, mods1, id.name.toTypeName)
22842284
else if (in.token == COMMA) {
22852285
in.nextToken()
2286-
val ids = commaSeparated(termIdent)
2286+
val ids = commaSeparated(() => termIdent())
22872287
PatDef(mods1, id :: ids, TypeTree(), EmptyTree)
22882288
}
22892289
else

0 commit comments

Comments
 (0)