Skip to content

Commit

Permalink
Allow cold values in static methods using parametricity
Browse files Browse the repository at this point in the history
Closes scala#14460

Allow cold arguments to be passed if the parameter is `!Matchable` and the method is global static.
  • Loading branch information
Xavientois committed Mar 22, 2022
1 parent e54a934 commit d719739
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 68 deletions.
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 }
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
}

0 comments on commit d719739

Please sign in to comment.