-
Notifications
You must be signed in to change notification settings - Fork 21
Forced to restate type argument boundaries #1786
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
Comments
Imported From: https://issues.scala-lang.org/browse/SI-1786?orig=1 |
karlw said: val a = i.myValue.intValue/2 // << error i is of type Any should be val a = i.myValue.intValue/2 // << error i.myValue is of type Any |
@odersky said: |
@som-snytt said: error: value intValue is not a member of _$1 At 2.9.1.final, error: value intValue is not a member of Any |
@paulp said: |
@adriaanm said (edited on Feb 11, 2014 7:56:58 PM UTC): reopened by: scala/scala#3509 |
Stephen Compall (s11001001) said (edited on Feb 11, 2014 8:27:54 PM UTC): |
@adriaanm said: |
@retronym said (edited on Dec 3, 2014 11:45:54 AM UTC): object Test {
type SerializableList[T <: Serializable] = List[T]
class C(val sl: SerializableList[_])
def unapply(x: C): Unit = Some.apply(x.sl) // type arguments [_$1] do not conform to type SerializableList's type parameter bounds [T <: Serializable]
} |
Dmytro Kondratiuk (dk14) said (edited on Dec 3, 2014 12:43:39 PM UTC): |
@retronym said: |
Dmytro Kondratiuk (dk14) said (edited on Dec 3, 2014 1:15:49 PM UTC): |
@retronym said: import TestRecursiveTypes._
import language.existentials
object TestRecursiveTypesScala {
def main(args: Array[String]): Unit = {
val impl = new UpperImpl()
impl.map().map().map()
val upper = new TestRecursiveTypes().provideUpper()
upper.map().map().map()
}
class Consumer extends UpperConsumer {
def consume(upper: Upper[_]): Unit = {
fbound(upper).map().map()
}
}
// Workaround for the limbo state given that:
// a) Java wildcard types propagate bounds (after the fix for https://issues.scala-lang.org/browse/SI-6169)
// b) Scala existentials don't https://issues.scala-lang.org/browse/SI-1786
def fbound(u: Upper[_]) = u.asInstanceOf[Upper[A] forSome { type A <: Upper[A] }]
} public class TestRecursiveTypes
{
// Base interface for F-Bounded polymorphism
public interface Upper<T extends Upper<T>>
{
public T map();
}
// Implementation of F-Bounded polymorphism
public static class UpperImpl implements Upper<UpperImpl>
{
@Override
public UpperImpl map()
{
System.out.println(String.format("map@%s",this));
return new UpperImpl();
}
}
// Consumer interface
public interface UpperConsumer
{
void consume(Upper<?> upper_);
}
// Consumer implementation
public static class Consumer implements UpperConsumer
{
@Override
public void consume(Upper<?> upper_)
{
upper_.map().map().map();
}
}
// Upper factory method, returns interface
public Upper<?> provideUpper()
{
return new UpperImpl();
}
public static void main(String[] args)
{
new TestRecursiveTypes().run();
}
private void run()
{
Upper<?> upper = new UpperImpl();
// This is also an upper, without conversio
Upper<?> mapped = upper.map();
Upper<?> upper2 = provideUpper();
new Consumer().consume(upper2.map().map().map());
}
}
|
see #11491 for some recent examples and discussion |
The below code shows a compiler flaw in that the wildcard "_" as value for a bounded type parameter either breaks the bound - as it result in Any - or doesn't (as id hoped it to be) evaluates to the bound.
The text was updated successfully, but these errors were encountered: