Skip to content

Commit ed4ce59

Browse files
Merge pull request #8910 from dotty-staging/fix-#8903
Fix #8903: Fix test for default parameters
2 parents 07780c1 + 41fbdc4 commit ed4ce59

File tree

3 files changed

+14
-3
lines changed

3 files changed

+14
-3
lines changed

compiler/src/dotty/tools/dotc/typer/Typer.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2900,6 +2900,7 @@ class Typer extends Namer
29002900
def dummyArg(tp: Type) = untpd.Ident(nme.???).withTypeUnchecked(tp)
29012901

29022902
def addImplicitArgs(using Context) = {
2903+
def hasDefaultParams = methPart(tree).symbol.hasDefaultParams
29032904
def implicitArgs(formals: List[Type], argIndex: Int, pt: Type): List[Tree] = formals match {
29042905
case Nil => Nil
29052906
case formal :: formals1 =>
@@ -2909,7 +2910,7 @@ class Typer extends Namer
29092910
val pt1 = pt.deepenProto
29102911
if ((pt1 `ne` pt) && constrainResult(tree.symbol, wtp, pt1)) implicitArgs(formals, argIndex, pt1)
29112912
else arg :: implicitArgs(formals1, argIndex + 1, pt1)
2912-
case failed: SearchFailureType if !tree.symbol.hasDefaultParams =>
2913+
case failed: SearchFailureType if !hasDefaultParams =>
29132914
// no need to search further, the adapt fails in any case
29142915
// the reason why we continue inferring arguments in case of an AmbiguousImplicits
29152916
// is that we need to know whether there are further errors.
@@ -2965,7 +2966,7 @@ class Typer extends Namer
29652966

29662967
// If method has default params, fall back to regular application
29672968
// where all inferred implicits are passed as named args.
2968-
if (methPart(tree).symbol.hasDefaultParams && !propFail.isInstanceOf[AmbiguousImplicits]) {
2969+
if hasDefaultParams && !propFail.isInstanceOf[AmbiguousImplicits] then
29692970
val namedArgs = wtp.paramNames.lazyZip(args).flatMap { (pname, arg) =>
29702971
if (arg.tpe.isError) Nil else untpd.NamedArg(pname, untpd.TypedSplice(arg)) :: Nil
29712972
}
@@ -2977,7 +2978,6 @@ class Typer extends Namer
29772978
} { (_, _) =>
29782979
issueErrors()
29792980
}
2980-
}
29812981
else issueErrors()
29822982
}
29832983
else tree match {

tests/run/i8903.check

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
done

tests/run/i8903.scala

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
object a {
2+
object home { def /(s: String) = createDir }
3+
object createDir {
4+
def createDirectoryIfNotExists(createParents: Boolean = false)(using attributes: Seq[String] = Seq.empty, linkOptions: Seq[String] = Seq.empty): Unit =
5+
println("done")
6+
}
7+
8+
//this line causes the crash
9+
@main def Test = (home/"temp").createDirectoryIfNotExists()
10+
}

0 commit comments

Comments
 (0)