-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Make explicit arguments for context bounds an error from 3.5 #19316
Conversation
There's a difference in neg/hidden-type-errors and a failure in ReplTests. Both look like some internals of quotes pass |
@nicolasstucki There was an error in - Error: /__w/dotty/dotty/scala2-library-tasty-tests/src/Main.scala:7:19 ------
Error: 7 | case Red, Green, Blue
Error: | ^
Error: |Context bounds will map to context parameters.
Error: |A `using` clause is needed to pass explicit arguments to them.
Error: |This code can be rewritten automatically under -rewrite -source 3.5-migration.
Error: one error found |
The reason is that we compile the standard library with this new mode. In particular the private[this] val $values: Array[Color] =
Array.apply[Color]([this.Red,this.Green,this.Blue : Color]*)(
scala.reflect.ClassTag.apply[Color](classOf[Color])) The solution is to make sure all desugarings that explicitly apply a context-bound set the This particular error can be fixed in private def ArrayLiteral(values: List[Tree], tpt: Tree)(using Context): Tree =
val clazzOf = TypeApply(ref(defn.Predef_classOf.termRef), tpt :: Nil)
val ctag = Apply(TypeApply(ref(defn.ClassTagModule_apply.termRef), tpt :: Nil), clazzOf :: Nil)
val apply = Select(ref(defn.ArrayModule.termRef), nme.apply)
- Apply(Apply(TypeApply(apply, tpt :: Nil), values), ctag :: Nil)
+ Apply(Apply(TypeApply(apply, tpt :: Nil), values), ctag :: Nil).setApplyKind(ApplyKind.Using) I pushed this fix to this PR. This fix makes |
2dd57a0
to
786852c
Compare
@nicolasstucki Ready for review. |
report.errorOrMigrationWarning( | ||
em"""Context bounds will map to context parameters. | ||
|A `using` clause is needed to pass explicit arguments to them.$rewriteMsg""", | ||
tree.srcPos, MigrationVersion(`3.4`, `3.5`)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This migration version should be defined in MigrationVersion.scala
as ExplicitContextBoundArgument
.
em"""Context bounds will map to context parameters. | ||
|A `using` clause is needed to pass explicit arguments to them.$rewriteMsg""", | ||
tree.srcPos, MigrationVersion(`3.4`, `3.5`)) | ||
if sourceVersion.isAtLeast(`3.5-migration`) then |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should use ExplicitContextBoundArgument.needsPatch
. It will use 3.4-migration
and check that the version is -migrating
.
&& isContextBoundParams | ||
&& pt.applyKind != ApplyKind.Using | ||
then | ||
def rewriteMsg = Message.rewriteNotice("This code", `3.5-migration`) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should use ExplicitContextBoundArgument
. See comment bellow.
def remedy = | ||
if ((prefix ++ suffix).isEmpty) "simply leave out the trailing ` _`" | ||
else s"use `$prefix<function>$suffix` instead" | ||
def rewrite = Message.rewriteNotice("This construct", `3.4-migration`) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be
def rewrite = Message.rewriteNotice("This construct", `3.4-migration`) | |
def rewrite = Message.rewriteNotice("This construct", MigrationVersion.FunctionUnderscore.warnVersion) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe rewriteNotice
should receive a MigrationVersion
instead. I will check that later an refactor all the use cases if needed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tests with warnings should now be added to tests/warn
.
tests/warn/context-bounds-migration.scala
class C[T]
def foo[X: C] = ()
given [T]: C[T] = C[T]()
def Test =
foo(C[Int]()) // warn
foo(using C[Int]()) // ok
* and migrations. | ||
*/ | ||
trait Migrations: | ||
this: Typer => |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am not convinced we should make this one a mixin. The one use case right now for typedAsFunction
, all other functions that are here and could go in here seem to be static.
I would suggest making Migrations
an object
and redefining Typer.typedAsFunction
as
def typedAsFunction(tree: untpd.PostfixOp, pt: Type)(using Context): Tree =
migrate(Migrations.typedAsFunction(tree, pt), throw new AssertionError("can't retype a PostfixOp"))
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think there's nothing wrong with a mixin, and the hack of passing an explicit typer is worse. Right now it only applies tp typedAsFunction
but I am sure that will not stay the only one.
@@ -158,6 +158,9 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer | |||
// Overridden in derived typers | |||
def newLikeThis(nestingLevel: Int): Typer = new Typer(nestingLevel) | |||
|
|||
// Overridden to do nothing in derived typers |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// Overridden to do nothing in derived typers | |
// Overridden to call `disabled` in derived typers |
Improves tests of scala#19316
Improves tests of #19316
Warning in 3.4. Rewrite available in 3.5-migration.
[test_scala2_library_tasty]