Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Spurious missing TypeTest instance for a match type #13433

Closed
neko-kai opened this issue Aug 31, 2021 · 1 comment · Fixed by #13453
Closed

Spurious missing TypeTest instance for a match type #13433

neko-kai opened this issue Aug 31, 2021 · 1 comment · Fixed by #13453
Assignees
Milestone

Comments

@neko-kai
Copy link
Contributor

Compiler version

3.0.1

Minimized code

https://scastie.scala-lang.org/R5e5jgGkSJ6fU7WTy4eqQw

import scala.reflect.TypeTest

type Matcher[A] = A match { case String => String }

def patternMatch[A](a: Any)(using tt: TypeTest[Any, Matcher[A]]): Option[Matcher[A]] = {
  // type T = RDF.Triple[Rdf]
  a match { 
    case res: Matcher[A] => Some(res)
    case _ => None
  }
}

def patternMatchWithAlias[A](a: Any)(using tt: TypeTest[Any, Matcher[A]]): Option[Matcher[A]] = {
  type T = Matcher[A]
  a match { 
    case res: T => Some(res)
    case _ => None
  }
}


@main def main = {
  println(patternMatch[String]("abc"))
  println(patternMatchWithAlias[String]("abc"))
  
  println(patternMatch[String](1))
  println(patternMatchWithAlias[String](1))
}

Output

the type test for Matcher[A] cannot be checked at runtime

Inside the body of patternMatch and subsequent failing type test:

Some(abc)
Some(abc)
Some(1)
None

However, the version of the code in patternMatchWithAlias works correctly and produces no warning. The only difference is a tautological alias

type T = Matcher[A]

and matching on the alias instead of the match type.

case res: T => res

Expectation

Expected both versions to work and to produce no spurious warnings:

the type test for Matcher[A] cannot be checked at runtime
the type test for Matcher[String] cannot be checked at runtime
@nicolasstucki
Copy link
Contributor

Same happens with ClassTag

nicolasstucki added a commit to dotty-staging/dotty that referenced this issue Sep 2, 2021
nicolasstucki added a commit to dotty-staging/dotty that referenced this issue Sep 2, 2021
nicolasstucki added a commit to dotty-staging/dotty that referenced this issue Sep 7, 2021
nicolasstucki added a commit to dotty-staging/dotty that referenced this issue Sep 9, 2021
nicolasstucki added a commit to dotty-staging/dotty that referenced this issue Oct 8, 2021
olsdavis pushed a commit to olsdavis/dotty that referenced this issue Apr 4, 2022
@Kordyjan Kordyjan added this to the 3.1.1 milestone Aug 2, 2023
EugeneFlesselle added a commit to dotty-staging/dotty that referenced this issue Apr 14, 2024
EugeneFlesselle added a commit to dotty-staging/dotty that referenced this issue Apr 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants