@@ -270,22 +270,25 @@ trait NamesDefaults { self: Analyzer =>
270270 */
271271 def argValDefs (args : List [Tree ], paramTypes : List [Type ], blockTyper : Typer ): List [Option [ValDef ]] = {
272272 val context = blockTyper.context
273- val symPs = map2(args, paramTypes)((arg, tpe ) => arg match {
273+ val symPs = map2(args, paramTypes)((arg, paramTpe ) => arg match {
274274 case Ident (nme.SELECTOR_DUMMY ) =>
275275 None // don't create a local ValDef if the argument is <unapply-selector>
276276 case _ =>
277- val byName = isByNameParamType(tpe )
278- val repeated = isScalaRepeatedParamType(tpe )
277+ val byName = isByNameParamType(paramTpe )
278+ val repeated = isScalaRepeatedParamType(paramTpe )
279279 val argTpe = (
280280 if (repeated) arg match {
281281 case Typed (expr, Ident (tpnme.WILDCARD_STAR )) => expr.tpe
282282 case _ => seqType(arg.tpe)
283283 }
284- else arg.tpe
285- ).widen // have to widen or types inferred from literal defaults will be singletons
284+ else
285+ // Note stabilizing can lead to a non-conformant argument when existentials are involved, e.g. neg/t3507-old.scala, hence the filter.
286+ gen.stableTypeFor(arg).filter(_ <:< paramTpe).getOrElse(arg.tpe)
287+ // We have to deconst or types inferred from literal arguments will be Constant(_), e.g. pos/z1730.scala.
288+ ).deconst
286289 val s = context.owner.newValue(unit.freshTermName(" x$" ), arg.pos, newFlags = ARTIFACT ) setInfo (
287- if (byName) functionType(Nil , argTpe) else argTpe
288- )
290+ if (byName) functionType(Nil , argTpe) else argTpe
291+ )
289292 Some ((context.scope.enter(s), byName, repeated))
290293 })
291294 map2(symPs, args) {
@@ -326,11 +329,10 @@ trait NamesDefaults { self: Analyzer =>
326329
327330 // type the application without names; put the arguments in definition-site order
328331 val typedApp = doTypedApply(tree, funOnly, reorderArgs(namelessArgs, argPos), mode, pt)
329- if (typedApp.isErrorTyped) tree
330- else typedApp match {
332+ typedApp match {
331333 // Extract the typed arguments, restore the call-site evaluation order (using
332334 // ValDef's in the block), change the arguments to these local values.
333- case Apply (expr, typedArgs) =>
335+ case Apply (expr, typedArgs) if ! (typedApp :: typedArgs).exists(_.isErrorTyped) => // bail out with erroneous args, see SI-7238
334336 // typedArgs: definition-site order
335337 val formals = formalTypes(expr.tpe.paramTypes, typedArgs.length, removeByName = false , removeRepeated = false )
336338 // valDefs: call-site order
@@ -358,6 +360,7 @@ trait NamesDefaults { self: Analyzer =>
358360 context.namedApplyBlockInfo =
359361 Some ((block, NamedApplyInfo (qual, targs, vargss :+ refArgs, blockTyper)))
360362 block
363+ case _ => tree
361364 }
362365 }
363366
0 commit comments