Skip to content

Commit 5ee801e

Browse files
authored
Backport "Handle default implicits to context parameters under -3.4-migration" (#19518)
Backports #19512
2 parents 600c525 + bc20aa6 commit 5ee801e

File tree

4 files changed

+17
-4
lines changed

4 files changed

+17
-4
lines changed

compiler/src/dotty/tools/dotc/printing/RefinedPrinter.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,7 @@ class RefinedPrinter(_ctx: Context) extends PlainPrinter(_ctx) {
309309
toText(tp.argType) ~ " ?=>? " ~ toText(tp.resultType)
310310
case tp @ FunProto(args, resultType) =>
311311
"[applied to ("
312-
~ keywordText("using ").provided(tp.isContextualMethod)
312+
~ keywordText("using ").provided(tp.applyKind == ApplyKind.Using)
313313
~ argsTreeText(args)
314314
~ ") returning "
315315
~ toText(resultType)

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

+4-2
Original file line numberDiff line numberDiff line change
@@ -106,12 +106,14 @@ trait Migrations:
106106
&& isContextBoundParams
107107
&& pt.applyKind != ApplyKind.Using
108108
then
109-
def rewriteMsg = Message.rewriteNotice("This code", mversion.patchFrom)
109+
def rewriteMsg =
110+
if pt.args.isEmpty then ""
111+
else Message.rewriteNotice("This code", mversion.patchFrom)
110112
report.errorOrMigrationWarning(
111113
em"""Context bounds will map to context parameters.
112114
|A `using` clause is needed to pass explicit arguments to them.$rewriteMsg""",
113115
tree.srcPos, mversion)
114-
if mversion.needsPatch then
116+
if mversion.needsPatch && pt.args.nonEmpty then
115117
patch(Span(pt.args.head.span.start), "using ")
116118
end contextBoundParams
117119

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

+4-1
Original file line numberDiff line numberDiff line change
@@ -3906,7 +3906,10 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
39063906
if (arg.tpe.isError) Nil else untpd.NamedArg(pname, untpd.TypedSplice(arg)) :: Nil
39073907
}
39083908
val app = cpy.Apply(tree)(untpd.TypedSplice(tree), namedArgs)
3909-
if (wtp.isContextualMethod) app.setApplyKind(ApplyKind.Using)
3909+
val needsUsing = wtp.isContextualMethod || wtp.match
3910+
case MethodType(ContextBoundParamName(_) :: _) => sourceVersion.isAtLeast(`3.4`)
3911+
case _ => false
3912+
if needsUsing then app.setApplyKind(ApplyKind.Using)
39103913
typr.println(i"try with default implicit args $app")
39113914
typed(app, pt, locked)
39123915
else issueErrors()

tests/neg/i19506.scala

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
//> using options "-source 3.4-migration",
2+
3+
trait Reader[T]
4+
def read[T: Reader](s: String, trace: Boolean = false): T = ???
5+
6+
def Test =
7+
read[Object]("") // error
8+
read[Object]("")() // error

0 commit comments

Comments
 (0)