diff options
Diffstat (limited to 'src')
4 files changed, 20 insertions, 4 deletions
diff --git a/src/compiler/scala/tools/nsc/typechecker/ContextErrors.scala b/src/compiler/scala/tools/nsc/typechecker/ContextErrors.scala index df0258832c..cb01faf619 100644 --- a/src/compiler/scala/tools/nsc/typechecker/ContextErrors.scala +++ b/src/compiler/scala/tools/nsc/typechecker/ContextErrors.scala @@ -1034,6 +1034,12 @@ trait ContextErrors { setError(arg) } else arg } + + def WarnAfterNonSilentRecursiveInference(param: Symbol, arg: Tree)(implicit context: Context) = { + val note = "type-checking the invocation of "+ param.owner +" checks if the named argument expression '"+ param.name + " = ...' is a valid assignment\n"+ + "in the current scope. The resulting type inference error (see above) can be fixed by providing an explicit type in the local definition for "+ param.name +"." + context.warning(arg.pos, note) + } def UnknownParameterNameNamesDefaultError(arg: Tree, name: Name)(implicit context: Context) = { issueNormalTypeError(arg, "unknown parameter name: " + name) diff --git a/src/compiler/scala/tools/nsc/typechecker/Infer.scala b/src/compiler/scala/tools/nsc/typechecker/Infer.scala index 5534cd179c..1c1adee343 100644 --- a/src/compiler/scala/tools/nsc/typechecker/Infer.scala +++ b/src/compiler/scala/tools/nsc/typechecker/Infer.scala @@ -617,7 +617,8 @@ trait Infer { } else if (argPos.contains(pos)) { // parameter specified twice namesOK = false } else { - positionalAllowed = false + if (index != pos) + positionalAllowed = false argPos(index) = pos } index += 1 diff --git a/src/compiler/scala/tools/nsc/typechecker/NamesDefaults.scala b/src/compiler/scala/tools/nsc/typechecker/NamesDefaults.scala index 9e6b9617a5..88e464a1f4 100644 --- a/src/compiler/scala/tools/nsc/typechecker/NamesDefaults.scala +++ b/src/compiler/scala/tools/nsc/typechecker/NamesDefaults.scala @@ -478,7 +478,14 @@ trait NamesDefaults { self: Analyzer => // instead of arg, but can't do that because eventually setType(ErrorType) // is called, and EmptyTree can only be typed NoType. Thus we need to // disable conforms as a view... - try typer.silent(_.typed(arg, subst(paramtpe))) match { + val errsBefore = reporter.ERROR.count + try typer.silent { tpr => + val res = tpr.typed(arg, subst(paramtpe)) + // better warning for SI-5044: if `silent` was not actually silent give a hint to the user + if (errsBefore < reporter.ERROR.count) + WarnAfterNonSilentRecursiveInference(param, arg)(context) + res + } match { case SilentResultValue(t) => !t.isErroneous // #4041 case _ => false } @@ -487,7 +494,7 @@ trait NamesDefaults { self: Analyzer => // CyclicReferences. Fix for #3685 case cr @ CyclicReference(sym, _) => (sym.name == param.name) && sym.accessedOrSelf.isVariable && { - NameClashError(sym, arg)(typer.context) + NameClashError(sym, arg)(context) true } } diff --git a/src/compiler/scala/tools/nsc/typechecker/Typers.scala b/src/compiler/scala/tools/nsc/typechecker/Typers.scala index 7419ec3bce..e40a567f1d 100644 --- a/src/compiler/scala/tools/nsc/typechecker/Typers.scala +++ b/src/compiler/scala/tools/nsc/typechecker/Typers.scala @@ -114,6 +114,8 @@ trait Typers extends Modes with Adaptations with Taggings { case MethodType(params, _) => val argResultsBuff = new ListBuffer[SearchResult]() val argBuff = new ListBuffer[Tree]() + // paramFailed cannot be initialized with params.exists(_.tpe.isError) because that would + // hide some valid errors for params preceding the erroneous one. var paramFailed = false def mkPositionalArg(argTree: Tree, paramName: Name) = argTree @@ -129,7 +131,7 @@ trait Typers extends Modes with Adaptations with Taggings { for(ar <- argResultsBuff) paramTp = paramTp.subst(ar.subst.from, ar.subst.to) - val res = if (paramFailed) SearchFailure else inferImplicit(fun, paramTp, context.reportErrors, false, context) + val res = if (paramFailed || (paramTp.isError && {paramFailed = true; true})) SearchFailure else inferImplicit(fun, paramTp, context.reportErrors, false, context) argResultsBuff += res if (res != SearchFailure) { |