-
Notifications
You must be signed in to change notification settings - Fork 40
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
::= syntax in covers #782
Comments
Runnable testcase: import math
// Does not build
Point: cover {
x, y: Float
norm ::= (this x pow(2.0f) + this y pow(2.0f)) sqrt()
}
main: func {
p := (2, 2) as Point
"norm of (2, 2) = #{p norm}" println()
} (Also, style note to @davidhesselbom - methods & getters should be lowercase in ooc - has nothing to do with the error but since I see that as a recurring pattern in your bug reports I thought I'd mention it). Here's clang's error report:
It's true that |
Issue in Official repo: ooc-lang#782
Sorry for noise, that commit does not work ... |
@zhaihj It doesn't look too bad though - how exactly does it not work? |
@fasterthanlime |
@fasterthanlime thanks for the style note, I appreciate it. We're converting a C# library into ooc, and we were toying with the idea of letting capitalization indicate which access modifier is used in the original code, hoping we would eventually be able to hack Rock to use these caps to insert actual access modifiers somewhere along the way. I'll keep it lowercase in bug reports from now on. |
Simply a matter of resolution order in properties. Fixed now, enjoy :) |
Can this be made to work for static properties as well? Or does it already? What would be the syntax, then? property: static := 1 ??? |
I would expect the syntax to be // The "static expr" is kinda funky but it actually works and is idiomatic in ooc
prop ::= static 1 (If it does work, that is) |
I know this was closed long ago, but I'm wondering about something related, and I don't think I should open a new issue about it. Here goes: Can covers have Vector: cover {
x, y: Int
init: func
}
Size: cover from Vector extends Vector {
init: func
width: Int {
get { this x }
set(value) { this x = value }
}
height: Int {
get { this y }
set(value) { this y = value }
}
} This doesn't build, because
and I'm not even sure what that means. The Vector: cover {
x, y: Int
init: func
}
Size: cover from Vector extends Vector {
init: func
width: Int { get { this x } }
height: Int { get { this y } }
}
v := Vector new()
v x = 1
v y = 2
s := v as Size
s width toString() println() // prints 1, yay
s height toString() println() // prints 2, yay Am I just missing an |
I hadn't thought about width: extern (x) Int
height: extern (y) Int which works, and which is obviously much, much better than width: Int {
get { this x }
set(value) { this x = value }
}
height: Int {
get { this y }
set(value) { this y = value }
} Thanks for watching, though. |
@davidhesselbom actually that's an interesting bug |
What is? The build error? Btw, do you still need the |
@davidhesselbom your Foo: cover {
bar: Int
baz: Int {
set (baz) { this bar = baz }
}
}
f: Foo
f bar = 1
f baz = 2
if (f bar != 2) {
raise("expected f bar == 2")
} ..but it actually works so it must be linked to the |
Whereas this doesn't work: UnderFoo: cover {
bar: Int
}
Foo: cover from UnderFoo extends UnderFoo {
baz: Int {
set (baz) { this bar = baz }
}
}
f: Foo
f bar = 1
f baz = 2
if (f bar != 2) {
raise("expected f bar == 2")
} |
Does it fail the test at the end, or does it simply not build? |
@davidhesselbom I opened #949 to track it, details are there — but I won't have time to close it in the near future |
Ok, thanks though. I'll ask again about the other thing: Is there an alternative to |
@davidhesselbom no alternative that I know of. an |
Okay, just making sure. Thanks! |
Why can't covers use the ::= syntax?
The text was updated successfully, but these errors were encountered: