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