Skip to content
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

Backport "Avoid stacked thisCall contexts" to LTS #21130

Merged
merged 1 commit into from
Jul 9, 2024
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
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/typer/Implicits.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1040,7 +1040,7 @@ trait Implicits:
trace(s"search implicit ${pt.show}, arg = ${argument.show}: ${argument.tpe.show}", implicits, show = true) {
record("inferImplicit")
assert(ctx.phase.allowsImplicitSearch,
if (argument.isEmpty) i"missing implicit parameter of type $pt after typer at phase ${ctx.phase.phaseName}"
if (argument.isEmpty) i"missing implicit parameter of type $pt after typer at phase ${ctx.phase}"
else i"type error: ${argument.tpe} does not conform to $pt${err.whyNoMatchStr(argument.tpe, pt)}")

val usableForInference = pt.exists && !pt.unusableForInference
Expand Down
27 changes: 17 additions & 10 deletions compiler/src/dotty/tools/dotc/typer/Typer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3752,7 +3752,9 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer

def dummyArg(tp: Type) = untpd.Ident(nme.???).withTypeUnchecked(tp)

def addImplicitArgs(using Context) = {
val origCtx = ctx

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
Expand Down Expand Up @@ -3872,15 +3874,20 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
case _ => retyped
else issueErrors(tree, args)
}
else tree match {
case tree: Block =>
readaptSimplified(tpd.Block(tree.stats, tpd.Apply(tree.expr, args)))
case tree: NamedArg =>
readaptSimplified(tpd.NamedArg(tree.name, tpd.Apply(tree.arg, args)))
case _ =>
readaptSimplified(tpd.Apply(tree, args))
}
}
else
inContext(origCtx):
// Reset context in case it was set to a supercall context before.
// otherwise the invariant for taking another this or super call context is not met.
// Test case is i20483.scala
tree match
case tree: Block =>
readaptSimplified(tpd.Block(tree.stats, tpd.Apply(tree.expr, args)))
case tree: NamedArg =>
readaptSimplified(tpd.NamedArg(tree.name, tpd.Apply(tree.arg, args)))
case _ =>
readaptSimplified(tpd.Apply(tree, args))
end addImplicitArgs

pt.revealIgnored match {
case pt: FunProto if pt.applyKind == ApplyKind.Using =>
// We can end up here if extension methods are called with explicit given arguments.
Expand Down
13 changes: 13 additions & 0 deletions tests/pos/i20483.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@

class Foo
(x: Option[String])
(using Boolean)
(using Int)
(using Double):

def this
(x: String)
(using Boolean)
(using Int)
(using Double) =
this(Some(x))