Skip to content

Instantly share code, notes, and snippets.

@milessabin
Created May 20, 2013 11:25
Show Gist options
  • Save milessabin/5611702 to your computer and use it in GitHub Desktop.
Save milessabin/5611702 to your computer and use it in GitHub Desktop.
Since when was "<:" an alias for "extends" ... not that I'm complaining, mind ;-)
scala> trait Foo ; trait Bar <: Foo
defined trait Foo
defined trait Bar
scala> implicitly[Bar <:< Foo]
res2: <:<[Bar,Foo] = <function1>
@oxbowlakes
Copy link

But (at least in 2.10.1):

scala> class Baz <: Bar
<console>:1: error: classes are not allowed to be virtual
       class Baz <: Bar
                 ^

@4lex1v
Copy link

4lex1v commented May 20, 2013

Also throws an error for abstract classes

@xuwei-k
Copy link

xuwei-k commented May 20, 2013

2.9.2 and 2.8.2 also works!

but 2.7.7

scala> trait Foo ; trait Bar <: Foo
<console>:1: error: ';' expected but '<:' found.
       trait Foo ; trait Bar <: Foo
                             ^

@milessabin
Copy link
Author

@larsrh discovered this in scalac,

if (in.token == EXTENDS ||
  settings.YvirtClasses && (mods hasFlag Flags.TRAIT) && in.token == SUBTYPE) { ...

So it looks like it's a relic of the virtual classes experiment.

@soc
Copy link

soc commented May 20, 2013

In general, it seems to be nice to have either <: or extends, not both.

@milessabin
Copy link
Author

This would appear to be the offending commit (search for YvirtClasses) scala/scala@4253124 ... calling @paulp ...

@milessabin
Copy link
Author

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