-
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
The number of super constructor arguments do not need to match #974
Comments
Isn't super ruby-like just forwarding its arguments? |
The compiler does forward all the arguments. You can find the related lines around rock/middle/FunctionCall.ooc: line 428. |
What if a zero-argument constructor is added in |
If change the test code to Base: abstract class {
value: Int
init: func (=value)
init: func~nodefault ()
}
Derived: class extends Base {
init: func (v: Int) {
super()
}
}
x := Derived new(3)
x value toString() println() It wil print |
Thanks for clearing that up - I don't recall it being possible to call So... modifying |
Yes, if you call However, currently compiler will ignore the suffixes of super, so if we have Base: abstract class {
init: func~a(arg1: Int)
init: func~b(arg2: Int)
}
|
The following patch makes diff --git a/source/rock/middle/FunctionCall.ooc b/source/rock/middle/FunctionCall.ooc
index 1049553..4a831b2 100644
--- a/source/rock/middle/FunctionCall.ooc
+++ b/source/rock/middle/FunctionCall.ooc
@@ -417,7 +417,7 @@ FunctionCall: class extends Expression {
fDecl := trail get(trail find(FunctionDecl), FunctionDecl)
superTypeDecl := fDecl owner getSuperRef()
finalScore := 0
- ref = superTypeDecl getMeta() getFunction(fDecl getName(), null, this, finalScore&)
+ ref = superTypeDecl getMeta() getFunction(fDecl getName(), this getSuffix(), this, finalScore&)
if(finalScore == -1) {
res wholeAgain(this, "something in our typedecl's functions needs resolving!")
return Response OK |
By the way, I would suggest using the super modifier in the function prototype if you need to call the super function anyways. If you do need to call it conditionally, using all the arguments would obviously be better form, since the addition of a zero argument version of the function would alter behavior. |
"the super modifier"? |
Yes, you can do something like: Foo: class {
init: func
doThing: func (x: Int) { "Called Foo doThing with #{x}" println() }
}
Bar: class extends Foo {
init: super func
doThing: super func
} It doesn't allow you to add call though, it's pretty much only useful to inherit constructors, since you are required to do it in some cases. |
IIRC the tutorial mentions this as a "hackish workaround"? |
I don't remember exactly, but perhaps the issue with the |
The implementation looks fine (does what I expect) to me and I don't particularly recall it being considered poor style. |
Here is a simple example:
Even though
Base
has no zero-argument constructor, this code still compiles and runs just fine. Thev
passed toDerived
constructor magically ends up invalue
.The text was updated successfully, but these errors were encountered: