Skip to content

Commit 02537a1

Browse files
committed
Merge remote-tracking branch 'origin/2.13.x' into faster/virtual-transform-minimal
2 parents 962112a + 9303e82 commit 02537a1

File tree

89 files changed

+414
-576
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

89 files changed

+414
-576
lines changed

src/compiler/scala/reflect/reify/phases/Reshape.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ trait Reshape {
227227
case NestedAnnotArg(ann) => toPreTyperAnnotation(ann)
228228
}
229229

230-
ann.assocs map { case (nme, arg) => AssignOrNamedArg(Ident(nme), toScalaAnnotation(arg)) }
230+
ann.assocs map { case (nme, arg) => NamedArg(Ident(nme), toScalaAnnotation(arg)) }
231231
}
232232

233233
def extractOriginal: PartialFunction[Tree, Tree] = { case Apply(Select(New(tpt), _), _) => tpt }

src/compiler/scala/tools/nsc/ast/parser/Parsers.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1979,7 +1979,7 @@ self =>
19791979
* }}}
19801980
*/
19811981
def pattern3(): Tree = {
1982-
val top = simplePattern(badPattern3)
1982+
val top = simplePattern(() => badPattern3())
19831983
val base = opstack
19841984
// See scala/bug#3189, scala/bug#4832 for motivation. Cf scala/bug#3480 for counter-motivation.
19851985
def isCloseDelim = in.token match {
@@ -1995,7 +1995,7 @@ self =>
19951995
case _ => EmptyTree
19961996
}
19971997
def loop(top: Tree): Tree = reducePatternStack(base, top) match {
1998-
case next if isIdent && !isRawBar => pushOpInfo(next) ; loop(simplePattern(badPattern3))
1998+
case next if isIdent && !isRawBar => pushOpInfo(next) ; loop(simplePattern(() => badPattern3()))
19991999
case next => next
20002000
}
20012001
checkWildStar orElse stripParens(loop(top))

src/compiler/scala/tools/nsc/ast/parser/Scanners.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -554,9 +554,9 @@ trait Scanners extends ScannersCommon {
554554
def fetchSingleQuote() = {
555555
nextChar()
556556
if (isIdentifierStart(ch))
557-
charLitOr(getIdentRest)
557+
charLitOr(() => getIdentRest())
558558
else if (isOperatorPart(ch) && (ch != '\\'))
559-
charLitOr(getOperatorRest)
559+
charLitOr(() => getOperatorRest())
560560
else if (!isAtEnd && (ch != SU && ch != CR && ch != LF || isUnicodeEscape)) {
561561
val isEmptyCharLit = (ch == '\'')
562562
getLitChar()

src/compiler/scala/tools/nsc/backend/jvm/BTypes.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -974,7 +974,7 @@ abstract class BTypes {
974974
}
975975
}
976976

977-
def reInitialize(): Unit = frontendSynch(isInit = false)
977+
def reInitialize(): Unit = frontendSynch { isInit = false }
978978
}
979979
}
980980

src/compiler/scala/tools/nsc/javac/JavaParsers.scala

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,7 @@ trait JavaParsers extends ast.parser.ParsersCommon with JavaScanners {
315315
if (in.token == LT) {
316316
in.nextToken()
317317
val t1 = convertToTypeId(t)
318-
val args = repsep(typeArg, COMMA)
318+
val args = repsep(() => typeArg(), COMMA)
319319
acceptClosingAngle()
320320
atPos(t1.pos) {
321321
val t2: Tree = AppliedTypeTree(t1, args)
@@ -401,7 +401,7 @@ trait JavaParsers extends ast.parser.ParsersCommon with JavaScanners {
401401
def typeParams(): List[TypeDef] =
402402
if (in.token == LT) {
403403
in.nextToken()
404-
val tparams = repsep(typeParam, COMMA)
404+
val tparams = repsep(() => typeParam(), COMMA)
405405
acceptClosingAngle()
406406
tparams
407407
} else List()
@@ -428,7 +428,7 @@ trait JavaParsers extends ast.parser.ParsersCommon with JavaScanners {
428428

429429
def formalParams(): List[ValDef] = {
430430
accept(LPAREN)
431-
val vparams = if (in.token == RPAREN) List() else repsep(formalParam, COMMA)
431+
val vparams = if (in.token == RPAREN) List() else repsep(() => formalParam(), COMMA)
432432
accept(RPAREN)
433433
vparams
434434
}
@@ -449,7 +449,7 @@ trait JavaParsers extends ast.parser.ParsersCommon with JavaScanners {
449449
def optThrows() {
450450
if (in.token == THROWS) {
451451
in.nextToken()
452-
repsep(typ, COMMA)
452+
repsep(() => typ(), COMMA)
453453
}
454454
}
455455

@@ -679,7 +679,7 @@ trait JavaParsers extends ast.parser.ParsersCommon with JavaScanners {
679679
def interfacesOpt() =
680680
if (in.token == IMPLEMENTS) {
681681
in.nextToken()
682-
repsep(typ, COMMA)
682+
repsep(() => typ(), COMMA)
683683
} else {
684684
List()
685685
}
@@ -711,7 +711,7 @@ trait JavaParsers extends ast.parser.ParsersCommon with JavaScanners {
711711
val parents =
712712
if (in.token == EXTENDS) {
713713
in.nextToken()
714-
repsep(typ, COMMA)
714+
repsep(() => typ(), COMMA)
715715
} else {
716716
List(javaLangObject())
717717
}

src/compiler/scala/tools/nsc/settings/ScalaSettings.scala

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,8 @@ trait ScalaSettings extends AbsScalaSettings
8989
def isScala212: Boolean = source.value >= version212
9090
private[this] val version213 = ScalaVersion("2.13.0")
9191
def isScala213: Boolean = source.value >= version213
92+
private[this] val version214 = ScalaVersion("2.14.0")
93+
def isScala214: Boolean = source.value >= version214
9294

9395
/**
9496
* -X "Advanced" settings
@@ -133,7 +135,7 @@ trait ScalaSettings extends AbsScalaSettings
133135
val sourceReader = StringSetting ("-Xsource-reader", "classname", "Specify a custom method for reading source files.", "")
134136
val reporter = StringSetting ("-Xreporter", "classname", "Specify a custom reporter for compiler messages.", "scala.tools.nsc.reporters.ConsoleReporter")
135137
val strictInference = BooleanSetting ("-Xstrict-inference", "Don't infer known-unsound types")
136-
val source = ScalaVersionSetting ("-Xsource", "version", "Treat compiler input as Scala source for the specified version, see scala/bug#8126.", initial = ScalaVersion("2.12"))
138+
val source = ScalaVersionSetting ("-Xsource", "version", "Treat compiler input as Scala source for the specified version, see scala/bug#8126.", initial = ScalaVersion("2.13"))
137139

138140
val XnoPatmatAnalysis = BooleanSetting ("-Xno-patmat-analysis", "Don't perform exhaustivity/unreachability analysis. Also, ignore @switch annotation.")
139141
val XfullLubs = BooleanSetting ("-Xfull-lubs", "Retains pre 2.10 behavior of less aggressive truncation of least upper bounds.")

src/compiler/scala/tools/nsc/transform/UnCurry.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -423,6 +423,7 @@ abstract class UnCurry extends InfoTransform
423423
def checkIsElidable(sym: Symbol): Boolean = (sym ne null) && sym.elisionLevel.exists { level =>
424424
if (sym.isMethod) level < settings.elidebelow.value
425425
else {
426+
// TODO: report error? It's already done in RefChecks. https://github.com/scala/scala/pull/5539#issuecomment-331376887
426427
if (settings.isScala213) reporter.error(sym.pos, s"${sym.name}: Only methods can be marked @elidable.")
427428
false
428429
}

src/compiler/scala/tools/nsc/transform/patmat/MatchOptimization.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ trait MatchOptimization extends MatchTreeMaking with MatchAnalysis {
104104
reusedTest <- test.reuses;
105105
nextDeps <- dependencies.get(reusedTest);
106106
diff <- (nextDeps -- currDeps).headOption;
107-
_ <- Some(currDeps = nextDeps))
107+
_ <- Some({ currDeps = nextDeps }))
108108
yield diff).nonEmpty
109109
}
110110

src/compiler/scala/tools/nsc/typechecker/ContextErrors.scala

Lines changed: 9 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -45,14 +45,6 @@ trait ContextErrors {
4545
case class NormalTypeError(underlyingTree: Tree, errMsg: String)
4646
extends TreeTypeError
4747

48-
/**
49-
* Marks a TypeError that was constructed from a CyclicReference (under silent).
50-
* This is used for named arguments, where we need to know if an assignment expression
51-
* failed with a cyclic reference or some other type error.
52-
*/
53-
class NormalTypeErrorFromCyclicReference(underlyingTree: Tree, errMsg: String)
54-
extends NormalTypeError(underlyingTree, errMsg)
55-
5648
case class AccessTypeError(underlyingTree: Tree, errMsg: String)
5749
extends TreeTypeError
5850

@@ -565,7 +557,7 @@ trait ContextErrors {
565557
}
566558
}
567559
val unknowns = (namelessArgs zip args) collect {
568-
case (_: Assign, AssignOrNamedArg(Ident(name), _)) => name
560+
case (_: Assign, NamedArg(Ident(name), _)) => name
569561
}
570562
val suppl =
571563
unknowns.size match {
@@ -1128,9 +1120,8 @@ trait ContextErrors {
11281120
// hence we (together with reportTypeError in TypeDiagnostics) make sure that this CyclicReference
11291121
// evades all the handlers on its way and successfully reaches `isCyclicOrErroneous` in Implicits
11301122
throw ex
1131-
case c @ CyclicReference(sym, info: TypeCompleter) =>
1132-
val error = new NormalTypeErrorFromCyclicReference(tree, typer.cyclicReferenceMessage(sym, info.tree) getOrElse ex.getMessage)
1133-
issueTypeError(error)
1123+
case CyclicReference(sym, info: TypeCompleter) =>
1124+
issueNormalTypeError(tree, typer.cyclicReferenceMessage(sym, info.tree) getOrElse ex.getMessage)
11341125
case _ =>
11351126
contextNamerErrorGen.issue(TypeErrorWithUnderlyingTree(tree, ex))
11361127
}
@@ -1322,23 +1313,12 @@ trait ContextErrors {
13221313
issueSymbolTypeError(sym, errMsg)
13231314
}
13241315

1325-
def AmbiguousReferenceInNamesDefaultError(arg: Tree, name: Name)(implicit context: Context) = {
1326-
if (!arg.isErroneous) { // check if name clash wasn't reported already
1327-
issueNormalTypeError(arg,
1328-
"reference to "+ name +" is ambiguous; it is both a method parameter "+
1329-
"and a variable in scope.")
1330-
setError(arg)
1331-
} else arg
1332-
}
1333-
1334-
def WarnAfterNonSilentRecursiveInference(param: Symbol, arg: Tree)(implicit context: Context) = {
1335-
val note = "failed to determine if '"+ param.name + " = ...' is a named argument or an assignment expression.\n"+
1336-
"an explicit type is required for the definition mentioned in the error message above."
1337-
context.warning(arg.pos, note)
1338-
}
1339-
1340-
def UnknownParameterNameNamesDefaultError(arg: Tree, name: Name)(implicit context: Context) = {
1341-
issueNormalTypeError(arg, "unknown parameter name: " + name)
1316+
def UnknownParameterNameNamesDefaultError(arg: Tree, name: Name, warnVariableInScope: Boolean)(implicit context: Context) = {
1317+
val suffix =
1318+
if (warnVariableInScope)
1319+
s"\nNote that assignments in argument position are no longer allowed since Scala 2.13.\nTo express the assignment expression, wrap it in brackets, e.g., `{ $name = ... }`."
1320+
else ""
1321+
issueNormalTypeError(arg, s"unknown parameter name: $name$suffix")
13421322
setError(arg)
13431323
}
13441324

src/compiler/scala/tools/nsc/typechecker/NamesDefaults.scala

Lines changed: 9 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,9 @@ trait NamesDefaults { self: Analyzer =>
5050
blockTyper: Typer
5151
) { }
5252

53-
private def nameOfNamedArg(arg: Tree) = Some(arg) collect { case AssignOrNamedArg(Ident(name), _) => name }
53+
private def nameOfNamedArg(arg: Tree) = Some(arg) collect { case NamedArg(Ident(name), _) => name }
5454
def isNamedArg(arg: Tree) = arg match {
55-
case AssignOrNamedArg(Ident(_), _) => true
55+
case NamedArg(Ident(_), _) => true
5656
case _ => false
5757
}
5858

@@ -452,7 +452,7 @@ trait NamesDefaults { self: Analyzer =>
452452
Apply(tree, args.map(_.duplicate)))
453453
Some(atPos(pos) {
454454
if (positional) default2
455-
else AssignOrNamedArg(Ident(p.name), default2)
455+
else NamedArg(Ident(p.name), default2)
456456
})
457457
}
458458
})
@@ -486,78 +486,6 @@ trait NamesDefaults { self: Analyzer =>
486486
} else NoSymbol
487487
}
488488

489-
/** A full type check is very expensive; let's make sure there's a name
490-
* somewhere which could potentially be ambiguous before we go that route.
491-
*/
492-
private def isAmbiguousAssignment(typer: Typer, param: Symbol, arg: Tree) = {
493-
import typer.context
494-
(context isNameInScope param.name) && {
495-
// for named arguments, check whether the assignment expression would
496-
// typecheck. if it does, report an ambiguous error.
497-
val paramtpe = param.tpe.cloneInfo(param)
498-
// replace type parameters by wildcard. in the below example we need to
499-
// typecheck (x = 1) with wildcard (not T) so that it succeeds.
500-
// def f[T](x: T) = x
501-
// var x = 0
502-
// f(x = 1) << "x = 1" typechecks with expected type WildcardType
503-
val udp = context.undetparams
504-
context.savingUndeterminedTypeParams(reportAmbiguous = false) {
505-
val subst = new SubstTypeMap(udp, udp map (_ => WildcardType)) {
506-
override def apply(tp: Type): Type = super.apply(dropByName(tp))
507-
}
508-
// This throws an exception which is caught in `tryTypedApply` (as it
509-
// uses `silent`) - unfortunately, tryTypedApply recovers from the
510-
// exception if you use errorTree(arg, ...) and conforms is allowed as
511-
// a view (see tryImplicit in Implicits) because it tries to produce a
512-
// new qualifier (if the old one was P, the new one will be
513-
// conforms.apply(P)), and if that works, it pretends nothing happened.
514-
//
515-
// To make sure tryTypedApply fails, we would like to pass EmptyTree
516-
// instead of arg, but can't do that because eventually setType(ErrorType)
517-
// is called, and EmptyTree can only be typed NoType. Thus we need to
518-
// disable conforms as a view...
519-
val errsBefore = reporter.ERROR.count
520-
try typer.silent { tpr =>
521-
val res = tpr.typed(arg.duplicate, subst(paramtpe))
522-
// better warning for scala/bug#5044: if `silent` was not actually silent give a hint to the user
523-
// [H]: the reason why `silent` is not silent is because the cyclic reference exception is
524-
// thrown in a context completely different from `context` here. The exception happens while
525-
// completing the type, and TypeCompleter is created/run with a non-silent Namer `context`
526-
// and there is at the moment no way to connect the two unless we go through some global state.
527-
if (errsBefore < reporter.ERROR.count)
528-
WarnAfterNonSilentRecursiveInference(param, arg)(context)
529-
res
530-
} match {
531-
case SilentResultValue(t) =>
532-
!t.isErroneous // #4041
533-
case SilentTypeError(e: NormalTypeErrorFromCyclicReference) =>
534-
// If we end up here, the CyclicReference was reported in a silent context. This can
535-
// happen for local definitions, when the completer for a definition is created during
536-
// type checking in silent mode. ContextErrors.TypeSigError catches that cyclic reference
537-
// and transforms it into a NormalTypeErrorFromCyclicReference.
538-
// The cycle needs to be reported, because the program cannot be typed: we don't know
539-
// if we have an assignment or a named arg.
540-
context.issue(e)
541-
// 'err = true' is required because we're in a silent context
542-
WarnAfterNonSilentRecursiveInference(param, arg)(context)
543-
false
544-
case _ =>
545-
// We got a type error, so it cannot be an assignment (it doesn't type check as one).
546-
false
547-
}
548-
catch {
549-
// `silent` only catches and returns TypeErrors which are not
550-
// CyclicReferences. Fix for #3685
551-
case cr @ CyclicReference(sym, _) =>
552-
(sym.name == param.name) && sym.accessedOrSelf.isVariable && {
553-
NameClashError(sym, arg)(context)
554-
true
555-
}
556-
}
557-
}
558-
}
559-
}
560-
561489
/** Removes name assignments from args. Additionally, returns an array mapping
562490
* argument indices from call-site-order to definition-site-order.
563491
*
@@ -590,23 +518,18 @@ trait NamesDefaults { self: Analyzer =>
590518
val argPos = Array.fill(args.length)(-1)
591519
val namelessArgs = {
592520
var positionalAllowed = true
593-
def stripNamedArg(arg: AssignOrNamedArg, argIndex: Int): Tree = {
594-
val AssignOrNamedArg(Ident(name), rhs) = arg
521+
def stripNamedArg(arg: NamedArg, argIndex: Int): Tree = {
522+
val NamedArg(Ident(name), rhs) = arg
595523
params indexWhere (p => matchesName(p, name, argIndex)) match {
596-
case -1 if positionalAllowed =>
597-
// prevent isNamed from being true when calling doTypedApply recursively,
598-
// treat the arg as an assignment of type Unit
599-
Assign(arg.lhs, rhs) setPos arg.pos
600524
case -1 =>
601-
UnknownParameterNameNamesDefaultError(arg, name)
525+
val warnVariableInScope = !settings.isScala214 && context0.lookupSymbol(name, _.isVariable).isSuccess
526+
UnknownParameterNameNamesDefaultError(arg, name, warnVariableInScope)
602527
case paramPos if argPos contains paramPos =>
603528
val existingArgIndex = argPos.indexWhere(_ == paramPos)
604529
val otherName = Some(args(paramPos)) collect {
605-
case AssignOrNamedArg(Ident(oName), _) if oName != name => oName
530+
case NamedArg(Ident(oName), _) if oName != name => oName
606531
}
607532
DoubleParamNamesDefaultError(arg, name, existingArgIndex+1, otherName)
608-
case paramPos if isAmbiguousAssignment(typer, params(paramPos), arg) =>
609-
AmbiguousReferenceInNamesDefaultError(arg, name)
610533
case paramPos if paramPos != argIndex =>
611534
positionalAllowed = false // named arg is not in original parameter order: require names after this
612535
argPos(argIndex) = paramPos // fix up the arg position
@@ -615,7 +538,7 @@ trait NamesDefaults { self: Analyzer =>
615538
}
616539
}
617540
mapWithIndex(args) {
618-
case (arg: AssignOrNamedArg, argIndex) =>
541+
case (arg: NamedArg, argIndex) =>
619542
val t = stripNamedArg(arg, argIndex)
620543
if (!t.isErroneous && argPos(argIndex) < 0) argPos(argIndex) = argIndex
621544
t

src/compiler/scala/tools/nsc/typechecker/RefChecks.scala

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1413,8 +1413,10 @@ abstract class RefChecks extends Transform {
14131413
}
14141414

14151415
def checkIsElidable(sym: Symbol): Unit = if (sym ne null) sym.elisionLevel.foreach { level =>
1416-
if (!sym.isMethod || sym.isAccessor || sym.isLazy || sym.isDeferred)
1417-
reporter.error(sym.pos, s"${sym.name}: Only methods can be marked @elidable.")
1416+
if (!sym.isMethod || sym.isAccessor || sym.isLazy || sym.isDeferred) {
1417+
val rest = if (sym.isDeferred) " The annotation affects only the annotated method, not overriding methods in subclasses." else ""
1418+
reporter.error(sym.pos, s"${sym.name}: Only concrete methods can be marked @elidable.$rest")
1419+
}
14181420
}
14191421
if (settings.isScala213) checkIsElidable(tree.symbol)
14201422

0 commit comments

Comments
 (0)