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

Certain types should not be eliminated by erasure #329

Closed
scabug opened this issue Dec 30, 2007 · 3 comments
Closed

Certain types should not be eliminated by erasure #329

scabug opened this issue Dec 30, 2007 · 3 comments

Comments

@scabug
Copy link

scabug commented Dec 30, 2007

The following code:

case class Foo(price: Int)
case class Bar(cost: Int)

def moo(in: AnyRef): String = in match {
	case p: {def price: Int} => "price "+p.price
	case c: {def cost: Int} => "cost "+c.cost
	case _ => "Unknown"
}

println(moo(Bar(33)))

results in the following compilation warnings:

pony:~/tmp dpp$$ scala -unchecked some3.scala 
(fragment of some3.scala):5: warning: refinement AnyRef{def price: Int} in type pattern is unchecked since it is eliminated by erasure
        case p: {def price: Int} => "price "+p.price
                 ^
(fragment of some3.scala):6: warning: refinement AnyRef{def cost: Int} in type pattern is unchecked since it is eliminated by erasure
        case c: {def cost: Int} => "cost "+c.cost
                 ^
two warnings found

However, the types can be discovered at runtime and should not be eliminated by erasure.

And yes, this could be considered an enhancement :-)

@scabug
Copy link
Author

scabug commented Dec 30, 2007

Imported From: https://issues.scala-lang.org/browse/SI-329?orig=1
Reporter: David Pollak (dpp)

@scabug
Copy link
Author

scabug commented Jun 11, 2012

@adriaanm said:
maybe parametric extractors and type tags could implement this outside of the compiler

@scabug
Copy link
Author

scabug commented Oct 11, 2012

@paulp said:
I'm going to close this as a duplicate of #6517.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants