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

Crash in case of virtual type conflicts #2318

Open
jcbrinfo opened this issue Sep 26, 2016 · 2 comments
Open

Crash in case of virtual type conflicts #2318

jcbrinfo opened this issue Sep 26, 2016 · 2 comments
Labels

Comments

@jcbrinfo
Copy link
Contributor

Just pass the following piece of code to any Nit engine and see it crash:

class A
    type X: Numeric
    fun foo: X do return 42
end
class B
super A
    redef type X: Int
end
class C
    super A
    redef type X: Float
end
class D
    super B
    super C
end
var y = new D
print y.foo

@egagnon: So, we can not refer to this case while discussing about virtual types support for now. 😄

@jcbrinfo jcbrinfo changed the title Nit crashes in case of virtual type conflicts Crash in case of virtual type conflicts Sep 26, 2016
@privat privat added the bug label Dec 6, 2016
@privat
Copy link
Member

privat commented Dec 8, 2016

Virtual types checks are not that nice in fact. The crash here is explicit by an abort since the conflict is detected. What is missing is 1. how to present the; 2. how to return the chain of methods and gracefully try to continue.
This is hard to do because the detection is quite deep in the semantic analysis.

In order to solve the bug I need to think what is the best error message to present to the programmer.
Is the bug in class D ? is the bug in y.foo ?

@jcbrinfo
Copy link
Contributor Author

jcbrinfo commented Dec 9, 2016

One way we can deal with this case for now is to force the developer to redefine X in D (in this particular example, no definition of D::X will be accepted in practice). However, if one day, we implement intersection types (which would solve a lot of problems for what I’m working on), we would be able to implicitly define D::X as the intersection of Int and Float and the error would be caught by the implicitly cast on the return value of foo.

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

No branches or pull requests

2 participants