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 9a48ebe
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
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
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 9a48ebe

Please sign in to comment.