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

Expected Warning not happening when using higher-kinded types #20412

Open
matheussbernardo opened this issue May 15, 2024 · 2 comments
Open

Expected Warning not happening when using higher-kinded types #20412

matheussbernardo opened this issue May 15, 2024 · 2 comments
Labels
area:reporting Error reporting including formatting, implicit suggestions, etc better-errors Issues concerned with improving confusing/unhelpful diagnostic messages itype:enhancement

Comments

@matheussbernardo
Copy link

matheussbernardo commented May 15, 2024

Compiler version

scalac -version
$ Scala compiler version 3.4.0 -- Copyright 2002-2024, LAMP/EPFL

Minimized example

trait T[A] {
  def v: A
}

trait T2[F[_], A] {
  def v: A
}

object doesntWarn {
  val x = new T2[Option, Int | String] {
    def v: Int | String = "asdf"
  }

  val y: T2[Option, Int] = x match {
    case z: T2[Option, Int] =>
      z
  }
}

object warns {
  val x = new T[Int | String] {
    def v: Int | String = "asdf"
  }

  val y: T[Int] = x match {
    case z: T[Int] =>
      z
  }
}

Output Error/Warning message

-- [E092] Pattern Match Unchecked Warning: Main.scala:26:9 ---------------------
26 |    case z: T[Int] =>
   |         ^
   |the type test for T[Int] cannot be checked at runtime because its type arguments can't be determined from T[Int | String]
   |
   | longer explanation available when compiling with `-explain`
1 warning found

Why this Error/Warning was not helpful

Hello! I am wondering why only the second example warns.
Is higher kinded-types messing with something here?
Is this expected?

Thanks in advance!

@matheussbernardo matheussbernardo added area:reporting Error reporting including formatting, implicit suggestions, etc better-errors Issues concerned with improving confusing/unhelpful diagnostic messages itype:enhancement stat:needs triage Every issue needs to have an "area" and "itype" label labels May 15, 2024
@Gedochao Gedochao removed the stat:needs triage Every issue needs to have an "area" and "itype" label label May 17, 2024
@Gedochao
Copy link

Hello! I am wondering why only the second example warns.
Is higher kinded-types messing with something here?
Is this expected?

I don't think this is expected.
We should investigate why this happens, thanks for reporting @matheussbernardo

@visox
Copy link

visox commented May 22, 2024

same problem here with 3.4.1 i think

....collectFirst{ case c@XResolved[JobTitle.type](_, _) => c}
[warn]    |                                              ^
[warn]    |the type test for ....XResolved[X.JobTitle.type]
[warn]    |  cannot be checked at runtime because its type arguments can't be determined from ....XResolved[X]
[warn]    |
[warn]    | longer explanation available when compiling with `-explain`
final case class XResolved[A <: X](
    column: A,
    id: String
)
case object JobTitle extends X

funny enough it still appears to work

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:reporting Error reporting including formatting, implicit suggestions, etc better-errors Issues concerned with improving confusing/unhelpful diagnostic messages itype:enhancement
Projects
None yet
Development

No branches or pull requests

3 participants