Skip to content

Commit d719739

Browse files
committed
Allow cold values in static methods using parametricity
Closes #14460 Allow cold arguments to be passed if the parameter is `!Matchable` and the method is global static.
1 parent e54a934 commit d719739

File tree

6 files changed

+12
-68
lines changed

6 files changed

+12
-68
lines changed

compiler/src/dotty/tools/dotc/transform/init/Semantic.scala

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1120,7 +1120,14 @@ object Semantic {
11201120

11211121
case Call(ref, argss) =>
11221122
// check args
1123-
val (errors, args) = evalArgs(argss.flatten, thisV, klass)
1123+
val (argErrors, args) = evalArgs(argss.flatten, thisV, klass)
1124+
// Allow cold args for static methods with non-matchable params
1125+
val methodType = ref.symbol.info.stripPoly
1126+
val allMatchable = methodType.paramInfoss.flatten.forall { (info) => info <:< defn.MatchableType }
1127+
val isStatic = ref.symbol.isStatic
1128+
val errors = if isStatic && allMatchable then
1129+
argErrors.filterNot(e => e.isInstanceOf[UnsafePromotion])
1130+
else argErrors
11241131

11251132
ref match
11261133
case Select(supert: Super, _) =>

tests/init/neg/enum-desugared.check

Lines changed: 0 additions & 18 deletions
This file was deleted.

tests/init/neg/enum-desugared.scala

Lines changed: 0 additions & 35 deletions
This file was deleted.

tests/init/neg/enum.check

Lines changed: 0 additions & 8 deletions
This file was deleted.

tests/init/neg/enum.scala

Lines changed: 0 additions & 6 deletions
This file was deleted.

tests/init/pos/inner-enum.scala

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
class Outer:
2+
enum MyEnum {
3+
case Case
4+
}

0 commit comments

Comments
 (0)