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

Infer refinement types for val members of traits and abstract classes #3964

Open
liufengyun opened this issue Feb 5, 2018 · 2 comments
Open
Assignees

Comments

@liufengyun
Copy link
Contributor

liufengyun commented Feb 5, 2018

Currently abstract member of trait or class will get a refinement type:

trait Animal
class Dog extends Animal
class Cat extends Animal

abstract class Bar { val x: Animal }
val bar: Bar { val x: Cat } = new Bar { val x = new Cat }

trait Foo { val x: Animal }
val foo: Foo { val x: Cat } = new Foo { val x = new Cat }

As argued by @julienrf , there should be a symmetry if the members are in the constructor positions:

abstract class Bar(val x: Animal)
val bar: Bar { val x: Cat } = new Bar(new Cat)

trait Foo(val x: Animal)
val foo: Foo { val x: Cat } = new Foo(new Cat)

Hopefully, this feature should also make the following work:

trait Vec(val size: Int)
class Vec8 extends Vec(8)

abstract class Lst(val size: Int)
class Lst8 extends Lst(8)

class Test {
  val v8a: Vec { val size: 8 } = new Vec8        // ok
  val v8b: Vec { val size: 8 } = new Vec(8)      // ok

  val l8a: Lst { val size: 8 } = new Lst8        // ok
  val l8b: Lst { val size: 8 } = new Lst(8)      // ok
}

Related #3920 .

@Blaisorblade
Copy link
Contributor

Wait, so you want Vec8 to not have a refinement? Can I add one by hand if I want to? How? This syntax looks odd:

class Vec8 extends Vec(8) { val size: 8 }

Also, it looks like I can write new Vec(8) but I can’t abstract it as a class... it’s good I can abstract it as a method, but how do you explain why one works and the other doesn’t to a user?

@liufengyun
Copy link
Contributor Author

@Blaisorblade Thanks for pointing out. That's a miscommunication, I think both should work.

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

No branches or pull requests

3 participants