Skip to content

Fix #8903: Fix test for default parameters #8910

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 8, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions compiler/src/dotty/tools/dotc/typer/Typer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2898,6 +2898,7 @@ class Typer extends Namer
def dummyArg(tp: Type) = untpd.Ident(nme.???).withTypeUnchecked(tp)

def addImplicitArgs(using Context) = {
def hasDefaultParams = methPart(tree).symbol.hasDefaultParams
def implicitArgs(formals: List[Type], argIndex: Int, pt: Type): List[Tree] = formals match {
case Nil => Nil
case formal :: formals1 =>
Expand All @@ -2907,7 +2908,7 @@ class Typer extends Namer
val pt1 = pt.deepenProto
if ((pt1 `ne` pt) && constrainResult(tree.symbol, wtp, pt1)) implicitArgs(formals, argIndex, pt1)
else arg :: implicitArgs(formals1, argIndex + 1, pt1)
case failed: SearchFailureType if !tree.symbol.hasDefaultParams =>
case failed: SearchFailureType if !hasDefaultParams =>
// no need to search further, the adapt fails in any case
// the reason why we continue inferring arguments in case of an AmbiguousImplicits
// is that we need to know whether there are further errors.
Expand Down Expand Up @@ -2963,7 +2964,7 @@ class Typer extends Namer

// If method has default params, fall back to regular application
// where all inferred implicits are passed as named args.
if (methPart(tree).symbol.hasDefaultParams && !propFail.isInstanceOf[AmbiguousImplicits]) {
if hasDefaultParams && !propFail.isInstanceOf[AmbiguousImplicits] then
val namedArgs = wtp.paramNames.lazyZip(args).flatMap { (pname, arg) =>
if (arg.tpe.isError) Nil else untpd.NamedArg(pname, untpd.TypedSplice(arg)) :: Nil
}
Expand All @@ -2975,7 +2976,6 @@ class Typer extends Namer
} { (_, _) =>
issueErrors()
}
}
else issueErrors()
}
else tree match {
Expand Down
1 change: 1 addition & 0 deletions tests/run/i8903.check
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
done
10 changes: 10 additions & 0 deletions tests/run/i8903.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
object a {
object home { def /(s: String) = createDir }
object createDir {
def createDirectoryIfNotExists(createParents: Boolean = false)(using attributes: Seq[String] = Seq.empty, linkOptions: Seq[String] = Seq.empty): Unit =
println("done")
}

//this line causes the crash
@main def Test = (home/"temp").createDirectoryIfNotExists()
}