-
-
Notifications
You must be signed in to change notification settings - Fork 409
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
Cannot assign to iftype-narrowed trait reference. #1960
Comments
That seems like the right behaviour to me. Say you have the trait val AST
trait val Method is AST
fun val with_changes(): Method
class val MethodNew is Method
fun val with_changes(): MethodNew =>
create()
class val MethodOther is Method
fun val with_changes(): MethodNew =>
MethodNew.create()
actor Main
new create(env: Env) =>
let ast = apply[MethodOther](MethodOther)
fun apply[A: AST val](ast': A): AST =>
var ast = ast'
iftype A <: Method then
ast = ast.with_changes()
end
ast If this did build, What you want here is a trait val AST
trait val Method[X] is AST
fun val with_changes(): X
class val MethodFun is Method[MethodFun]
fun val with_changes(): MethodFun => create()
class val MethodBe is Method[MethodBe]
fun val with_changes(): MethodBe => create()
class val MethodNew is Method[MethodNew]
fun val with_changes(): MethodNew => create()
actor Main
new create(env: Env) =>
let ast = apply[MethodFun](MethodFun)
fun apply[A: AST val](ast': A): AST =>
var ast = ast'
iftype A <: Method[A] then
ast = ast.with_changes()
end
ast This is still not working, but I'm not sure why.
The compiler thinks the |
This is interesting. trait val AST
trait val Method[X] is AST
fun val with_changes(): X
actor Main
new create(env: Env) => None
fun foo[A: Method[A] val](ast: A) : A =>
ast.with_changes()
fun apply[A: AST val](ast': A): AST =>
var ast = ast'
iftype A <: Method[A] then
ast = foo[A](ast.with_changes())
end
ast
Which results in this sort of "desugaring" fun apply[Aouter: AST val](ast': Aouter): AST =>
var ast = ast'
iftype [Ainner: AST val & Method[Aouter] val] =>
ast = foo[Ainner](ast.with_changes()) And the error message would then be Similarly, this doesn't work now, but I believe it should trait val Method[X: Method[X]]
actor Main
new create(env: Env) => None
fun apply[X]() =>
iftype X <: Method[X] then
None
end
|
By defining the shadowing TK_TYPEPARAM on the entire iftype clause, which contains both the constraint and the body, the appropriate definition of the type variable is used when it appears in the constraint. Fixes ponylang#1960
By defining the shadowing TK_TYPEPARAM on the entire iftype clause, which contains both the constraint and the body, the appropriate definition of the type variable is used when it appears in the constraint. Fixes ponylang#1960
* Keep the data of TK_TYPEPARAM pointing to the original definition. iftype is implemented by shadowing the type parameter with a new definition and a new constraint. Storing the pointer of the original definition allows us to compare identity of type parameters easily. This replaces the more complicated subtyping-based check to determine whether a type parameter should be reified. * Create a new AST node for iftype clauses. This creates a new scope with both the constraint and the body of the iftype, but without the else clause. * Fix support for recursive constraints in iftype conditions. By defining the shadowing TK_TYPEPARAM on the entire iftype clause, which contains both the constraint and the body, the appropriate definition of the type variable is used when it appears in the constraint. Fixes #1960 * Rename TK_IFTYPE and TK_IFTYPE_CLAUSE to be clearer
I ran into this odd error with
iftype
, where it is disallowing an assignment to an iftype-narrowed reference ~~~that should be allowed~~~.EDIT: @plietar demonstrated why this shouldn't be allowed, but also found some other related issues, so this ticket remains open.
Note that this works fine if I remove the intermediate
Method
trait, and use one of the specific classes directly as the supertype in theiftype
clause:The text was updated successfully, but these errors were encountered: