Skip to content

Conversation

@tanishiking
Copy link
Member

Fix #25000

The wildcardArgOK function in overload resolution would crash with a MatchError when the argument type had mixed wildcard and concrete type arguments on an invariant type (e.g., java.util.Map[String, ? <: V]).

The partial function only handled TypeBounds but String is a TypeRef, causing the pattern match to fail. Added a general case that returns true if two types are same for non-wildcard arguments.

Maybe we should return true here and defer their validation to the main isCompatible check?

@tanishiking
Copy link
Member Author

We still have an overload checking regression when both formal and argtpe are TypeBounds

trait Format
trait Codec[L, H, F <: Format]  // invariant

trait Variant[O] {
  def codec: Codec[?, O, ? <: Format]
}

class Test {
  def decode[L, H](codec: Codec[L, H, ? <: Format]): H = ???
  def decode[L, H](other: String): H = ???

  def test[O](v: Variant[O]): O = decode(v.codec)
  // None of the overloaded alternatives of method decode in class Test with types
  //  [L, H](other: String): H
  //  [L, H](codec: Codec[L, H, ? <: Format]): H
  // match arguments ((v.codec² : => Codec[?, O, ? <: Format]))
  // 
  // where:    codec  is a reference to a value parameter
  //           codec² is a method in trait Variant
  //
  // v.codec: Codec[?, O, ? <: Format]
  // formal:  Codec[L, H, ? <: Format]
  // Pairs: (?, L), (O, H), (? <: Format, ? <: Format)
  //
}

Fix scala#25000

The `wildcardArgOK` function in overload resolution would crash with a
MatchError when the argument type had mixed wildcard and concrete type
arguments on an invariant type (e.g., `java.util.Map[String, ? <: V]`).

The partial function only handled `TypeBounds` but `String` is a `TypeRef`,
causing the pattern match to fail. Added a general case that returns
`true` if two types are same for non-wildcard arguments.

Maybe we should return true here and defer their validation to the main
`isCompatible` check?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Compiler crash (MatchError) in overload resolution with mixed wildcard/concrete type arguments

1 participant