Skip to content

Commit 7b1f4f3

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

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-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, _) =>

0 commit comments

Comments
 (0)