stmt/class: elide extra scope when calling parent ctor

This commit is contained in:
mappu 2020-04-05 19:12:42 +12:00
parent 28937fc384
commit 564be76bef

10
node.go
View File

@ -418,15 +418,13 @@ func (this *conversionState) convert(n_ node.Node) (string, error) {
// within the constructor, but, our generated code will never do that
// TODO replace our NewX constructors with split NewX + newXInPlace(??)
// Use a child scope for the temporary name
ret := "{\n"
ret += "super, err := " + constructorName(this.currentClassParentName) + funcArgs + "\n"
// No need to use a child scope for the temporary name -
// super() is a reserved name in PHP anyway
ret := "super, err := " + constructorName(this.currentClassParentName) + funcArgs + "\n"
ret += "if err != nil {\n"
ret += "return err\n"
ret += "}\n"
ret += "this." + this.currentClassParentName + " = *super\n"
ret += "}\n"
ret += "\n"
ret += "this." + this.currentClassParentName + " = *super // copy by value\n"
return ret, nil
}
}