Skip to content

Commit 9a48ebe

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 9a48ebe

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
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/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)