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

dealias types when looking for uncheckable outer checks #6813

Open
scabug opened this issue Dec 14, 2012 · 14 comments
Open

dealias types when looking for uncheckable outer checks #6813

scabug opened this issue Dec 14, 2012 · 14 comments
Labels
dealias compiler isn't dealiasing when it should, or vice versa enhancement patmat usability
Milestone

Comments

@scabug
Copy link

scabug commented Dec 14, 2012

Following pattern match:

scala> import scala.reflect.runtime.universe._
import scala.reflect.runtime.universe._

scala> Flag.IMPLICIT match { case f: FlagSet => "flag"; case l: Long => "long" }
warning: there were 1 unchecked warnings; re-run with -unchecked for details
res2: String = long

Should return "flag". Class tag (FlagSetTag) is imported and in scope so it looks like pattern matching bug.

@scabug
Copy link
Author

scabug commented Dec 14, 2012

Imported From: https://issues.scala-lang.org/browse/SI-6813?orig=1
Reporter: @densh
Affected Versions: 2.10.0-RC5

@scabug
Copy link
Author

scabug commented Dec 14, 2012

@paulp said:

type FlagSet = Long

It would sure be news to me if the pattern matcher had any chance of distinguishing "FlagSet" from "Long".

@scabug
Copy link
Author

scabug commented Dec 14, 2012

@adriaanm said:
but then you shouldn't get an unchecked warning, now should you?

@scabug
Copy link
Author

scabug commented Dec 14, 2012

@paulp said:
It might be reasonable to warn there (sometimes - sometimes not - hard to say exactly when) but yes, it probably shouldn't be warning that "The outer reference in this type test cannot be checked at run time" given that the type test is "Int". That suggests a wider-ranging bug, in that the type alias is dealiased for the type test, but the unchecked warning makes reference to the $outer of the type alias. These outers are unrelated!

@scabug
Copy link
Author

scabug commented Dec 14, 2012

@paulp said:
I mean the type test is "Long", point unaffected.

@scabug
Copy link
Author

scabug commented Dec 14, 2012

@adriaanm said (edited on Dec 14, 2012 9:42:44 PM UTC):
ah, sorry -- i had foolishly assumed the unchecked warning was about an abstract type, instead it was the uncheckable outer reference

yes, the outer check should operate on the dealiased type and thus not warn

@scabug
Copy link
Author

scabug commented Dec 14, 2012

@xeno-by said (edited on Dec 14, 2012 9:52:47 PM UTC):
I have to admit, I don't quite get the verdict. Is the pattern matching behavior considered to a bug? Or it's just a warning which is deemed to be a bug? Or both?

@scabug
Copy link
Author

scabug commented Dec 14, 2012

@paulp said:
The warning is a bug; the pattern matcher behavior is as specified, despite being undesirable. Unless there's some reason it couldn't be done of which I am not aware, it is a design failure in reflection that FlagSet is a type alias and not a value class - the latter would have all the advantages of being a type alias without disadvantages like this one.

@scabug
Copy link
Author

scabug commented Jun 29, 2014

Ivan Macek (imacek) said:
Hi all, I'm also getting "The outer reference in this type test cannot be checked at run time" errors when pattern matching by type and using aliasing objects.
Here is the example 40 line code example: https://gist.github.com/IvanMacek/c2456c1401176051dbf9

Is this the same issue as the one reported here?

Thanks for help!

@scabug
Copy link
Author

scabug commented Jun 18, 2015

Age Mooij (agemooij) said (edited on Jun 18, 2015 4:53:48 PM UTC):
Hey guys. I think I just ran into this one too with a new case, or at least one that hasn't been explicitly mentioned yet.

In short: I'm getting the dreaded warning when using a subtype of an object that I have aliased in a pattern match, which in my case involves an unapplySeq call. Real world code snippet:

case Path.Segment(prefix, tail)  ...

where Path is a type alias defined in a package object as:

  type Path = spray.http.Uri.Path
  val Path = spray.http.Uri.Path

Any progress on this issue?

Scala version: 2.11.6

@dwijnand
Copy link
Member

dwijnand commented Jan 25, 2021

scala> Flag.IMPLICIT match { case f: FlagSet => "flag"; case l: Long => "long" }
warning: there were 1 unchecked warnings; re-run with -unchecked for details
res2: String = long

No longer reproduces:

Welcome to Scala 2.13.4 (OpenJDK 64-Bit Server VM, Java 11.0.9).
Type in expressions for evaluation. Or try :help.
import scala.reflect.runtime.universe._

scala> import scala.reflect.runtime.universe._
import scala.reflect.runtime.universe._

scala> Flag.IMPLICIT match { case f: FlagSet => "flag"; case l: Long => "long" }
val res0: String = flag

@dwijnand
Copy link
Member

Note how it now just returns "flag" not "long", so I assume whatever fixed that also fixed the warning.

@SethTisue SethTisue removed this from the Backlog milestone Jan 25, 2021
@paulp
Copy link

paulp commented Jan 28, 2021

OTOH, a FlagSet isn't a Long and a Long isn't a FlagSet:

scala> Flag.IMPLICIT: Long
            ^
       error: type mismatch;
        found   : reflect.runtime.universe.FlagSet
        required: Long

scala> 5L: FlagSet
       ^
       error: type mismatch;
        found   : Long(5L)
        required: reflect.runtime.universe.FlagSet
        

If the scrutinee is a Long, it's an error to have a FlagSet case:

scala> 5L match { case l: Long => "long" ; case f: FlagSet => "flag" }
                                                   ^
       error: scrutinee is incompatible with pattern type;
        found   : reflect.runtime.universe.FlagSet
        required: Long
                                                 ^
       error: type mismatch;
        found   : reflect.runtime.universe.FlagSet
        required: Long

If the scrutinee is a FlagSet, it matches a Long case with no warning, and the presumably unreachable FlagSet case is also allowed.

scala> Flag.IMPLICIT match { case l: Long => "long" ; case f: FlagSet => "flag" }
val res0: String = long

@dwijnand dwijnand reopened this Jan 28, 2021
@dwijnand
Copy link
Member

Hmm, good points, Paul, thank you. I closed this in passing by, so let me take your notes and review it better.

@scala scala deleted a comment from scabug Jan 29, 2021
@SethTisue SethTisue added this to the Backlog milestone Mar 11, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
dealias compiler isn't dealiasing when it should, or vice versa enhancement patmat usability
Projects
None yet
Development

No branches or pull requests

4 participants