let methods be inline

This commit is contained in:
2026-07-05 13:26:47 +10:00
parent 10239ab44e
commit ccd6fd314e
2 changed files with 14 additions and 31 deletions

View File

@@ -3623,10 +3623,20 @@ ResultType(CometOperand, ErrorMessage) visitMethodDefStatement(CometCompiler* c,
false
);
// build the functions body
ResultType(CometOperand, ErrorMessage) bodyResult = compile(c, funcDef.program);
if (bodyResult.error)
return bodyResult;
if (funcDef.inlineExpr != NULL) { // its an inline function
// build the functions body
ResultType(CometOperand, ErrorMessage) exprResult = compile(c, funcDef.inlineExpr);
if (exprResult.error)
return exprResult;
// then return
buildReturn(c);
} else {
// build the functions body
ResultType(CometOperand, ErrorMessage) bodyResult = compile(c, funcDef.program);
if (bodyResult.error)
return bodyResult;
}
// return back to the parent scope
c->env = destroyEnv(c->env);

View File

@@ -1,27 +0,0 @@
struct Foo {
init() {
}
func foo() -> int {
return 2 + 6
}
}
struct Child : Foo {
override func foo() -> int {
return 2 + 4
}
init() {
}
}
func main() -> int {
Child test = new Child()
return test.foo()
}