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

Handle default implicits to context parameters under -3.4-migration #19512

Merged
merged 1 commit into from
Jan 23, 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
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ class RefinedPrinter(_ctx: Context) extends PlainPrinter(_ctx) {
toText(tp.argType) ~ " ?=>? " ~ toText(tp.resultType)
case tp @ FunProto(args, resultType) =>
"[applied to ("
~ keywordText("using ").provided(tp.isContextualMethod)
~ keywordText("using ").provided(tp.applyKind == ApplyKind.Using)
~ argsTreeText(args)
~ ") returning "
~ toText(resultType)
Expand Down
6 changes: 4 additions & 2 deletions compiler/src/dotty/tools/dotc/typer/Migrations.scala
Original file line number Diff line number Diff line change
Expand Up @@ -106,12 +106,14 @@ trait Migrations:
&& isContextBoundParams
&& pt.applyKind != ApplyKind.Using
then
def rewriteMsg = Message.rewriteNotice("This code", mversion.patchFrom)
def rewriteMsg =
if pt.args.isEmpty then ""
else Message.rewriteNotice("This code", mversion.patchFrom)
report.errorOrMigrationWarning(
em"""Context bounds will map to context parameters.
|A `using` clause is needed to pass explicit arguments to them.$rewriteMsg""",
tree.srcPos, mversion)
if mversion.needsPatch then
if mversion.needsPatch && pt.args.nonEmpty then
patch(Span(pt.args.head.span.start), "using ")
end contextBoundParams

Expand Down
5 changes: 4 additions & 1 deletion compiler/src/dotty/tools/dotc/typer/Typer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3906,7 +3906,10 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
if (arg.tpe.isError) Nil else untpd.NamedArg(pname, untpd.TypedSplice(arg)) :: Nil
}
val app = cpy.Apply(tree)(untpd.TypedSplice(tree), namedArgs)
if (wtp.isContextualMethod) app.setApplyKind(ApplyKind.Using)
val needsUsing = wtp.isContextualMethod || wtp.match
case MethodType(ContextBoundParamName(_) :: _) => sourceVersion.isAtLeast(`3.4`)
case _ => false
if needsUsing then app.setApplyKind(ApplyKind.Using)
typr.println(i"try with default implicit args $app")
typed(app, pt, locked)
else issueErrors()
Expand Down
8 changes: 8 additions & 0 deletions tests/neg/i19506.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
//> using options "-source:3.4-migration",

trait Reader[T]
def read[T: Reader](s: String, trace: Boolean = false): T = ???

def Test =
read[Object]("") // error
read[Object]("")() // error
Loading