Skip to content

Allow cold values in static methods using parametricity #14751

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

Closed
Closed
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
9 changes: 8 additions & 1 deletion compiler/src/dotty/tools/dotc/transform/init/Semantic.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1120,7 +1120,14 @@ object Semantic {

case Call(ref, argss) =>
// check args
val (errors, args) = evalArgs(argss.flatten, thisV, klass)
val (argErrors, args) = evalArgs(argss.flatten, thisV, klass)
// Allow cold args for static methods with non-matchable params
val methodType = ref.symbol.info.stripPoly
val allMatchable = methodType.paramInfoss.flatten.forall { (info) => info <:< defn.MatchableType }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we wanted to do the check per-argument rather than for all the arguments. That is, in def call, we have

      def checkArgs = args.flatMap(_.promote)

There we want to promote only those args that correspond to non-matchable params. Even if some params are matchable, the call is still fine as long as we can promote the args that correspond to those params.

val isStatic = ref.symbol.isStatic
val errors = if isStatic && allMatchable then
argErrors.filterNot(e => e.isInstanceOf[UnsafePromotion])
else argErrors

ref match
case Select(supert: Super, _) =>
Expand Down
18 changes: 0 additions & 18 deletions tests/init/neg/enum-desugared.check

This file was deleted.

35 changes: 0 additions & 35 deletions tests/init/neg/enum-desugared.scala

This file was deleted.

8 changes: 0 additions & 8 deletions tests/init/neg/enum.check

This file was deleted.

6 changes: 0 additions & 6 deletions tests/init/neg/enum.scala

This file was deleted.

4 changes: 4 additions & 0 deletions tests/init/pos/inner-enum.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
class Outer:
enum MyEnum {
case Case
}