Skip to content
Merged
Show file tree
Hide file tree
Changes from 18 commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
9ddbb08
Optimize Lua type assurance boundaries
Frotty Sep 2, 2026
d58a6d2
Preserve generic defaults and boolean values
Frotty Sep 2, 2026
2cf295e
Fix Lua boolean and generic default normalization
Frotty Sep 2, 2026
ea8b239
Normalize generic values used as Lua indices
Frotty Sep 2, 2026
caf7a4e
Normalize erased generic range bounds
Frotty Sep 2, 2026
dcf8da5
Normalize erased generic switch values
Frotty Sep 2, 2026
f09ee16
Preserve stacktraces in Lua assurance calls
Frotty Sep 2, 2026
3eb9de4
Normalize erased generic closure results
Frotty Sep 2, 2026
c99af94
Normalize erased generic statement block results
Frotty Sep 2, 2026
b94d7e6
Propagate range types into expression children
Frotty Sep 2, 2026
e101e63
Use selected overload type for erased arguments
Frotty Sep 2, 2026
5920bf9
Fix erased generic propagation in composite Lua expressions
Frotty Sep 2, 2026
5f21848
Cover unary erased generic closure results
Frotty Sep 2, 2026
24246be
Propagate selected types through composite Lua arguments
Frotty Sep 2, 2026
5c72fae
Propagate concrete types through Lua composite operands
Frotty Sep 2, 2026
510b152
Fix erased operands in Lua composite expressions
Frotty Sep 2, 2026
72489bc
Propagate selected types into statement blocks
Frotty Sep 2, 2026
dc1b299
Preserve normalization for primitive array reads
Frotty Sep 2, 2026
5afe445
Propagate closure types through statement blocks
Frotty Sep 2, 2026
1d54bb4
Finish Lua type assurance boundaries
Frotty Sep 2, 2026
6c7257c
Merge remote-tracking branch 'origin/master' into codex/lua-type-assu…
Frotty Sep 2, 2026
37453da
Handle varargs in constructor assurance
Frotty Sep 2, 2026
053c8e0
Unify constructor vararg assurance
Frotty Sep 2, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import de.peeeq.wurstscript.WLogger;
import de.peeeq.wurstscript.ast.*;
import de.peeeq.wurstscript.attributes.names.FuncLink;
import de.peeeq.wurstscript.types.*;
import de.peeeq.wurstscript.utils.Utils;
import org.eclipse.jdt.annotation.NonNull;
Expand Down Expand Up @@ -46,6 +47,14 @@ public class AttrExprExpectedType {
return varDef.attrTyp();
} else if (parent instanceof ExprBinary) {
ExprBinary exprBinary = (ExprBinary) parent;
if (exprBinary.attrFuncLink() != null) {
FunctionSignature signature = FunctionSignature.fromNameLink(exprBinary.attrFuncLink());
if (exprBinary.getLeft() == expr && signature.getReceiverType() != null) {
return signature.getReceiverType();
} else if (exprBinary.getRight() == expr && !signature.getParamTypes().isEmpty()) {
return signature.getParamType(0);
}
}
WurstType leftType = exprBinary.getLeft().attrTyp();
WurstType rightType = exprBinary.getRight().attrTyp();
if (leftType.equalsType(rightType, expr)) {
Expand All @@ -72,10 +81,44 @@ public class AttrExprExpectedType {
}
} else if (parent instanceof StmtReturn) {
StmtReturn stmtReturn = (StmtReturn) parent;
if (stmtReturn.getParent() instanceof ExprStatementsBlock) {
ExprStatementsBlock block = (ExprStatementsBlock) stmtReturn.getParent();
WurstType expectedType = block.attrExpectedTypRaw();
if (expectedType instanceof WurstTypeUnknown
&& block.getParent() instanceof ExprClosure) {
FuncLink abstractMethod = ((ExprClosure) block.getParent()).attrClosureAbstractMethod();
if (abstractMethod != null) {
return abstractMethod.getReturnType();
}
}
return expectedType;
}
FunctionImplementation nearestFuncDef = stmtReturn.attrNearestFuncDef();
if (nearestFuncDef != null) {
return nearestFuncDef.attrReturnTyp();
}
} else if (parent instanceof StmtForRange) {
StmtForRange forRange = (StmtForRange) parent;
if (forRange.getTo() == expr || forRange.getStep() == expr) {
return WurstTypeInt.instance();
}
} else if (parent instanceof ExprStatementsBlock) {
ExprStatementsBlock block = (ExprStatementsBlock) parent;
if (block.getReturnStmt() != null && block.getReturnStmt().getReturnedObj() == expr) {
return block.attrExpectedTypRaw();
}
} else if (parent instanceof Indexes) {
return WurstTypeInt.instance();
} else if (parent instanceof SwitchStmt) {
SwitchStmt switchStmt = (SwitchStmt) parent;
if (switchStmt.getExpr() == expr) {
for (SwitchCase switchCase : switchStmt.getCases()) {
for (Expr caseExpr : switchCase.getExpressions()) {
WurstType type = caseExpr.attrTyp();
return type instanceof WurstTypeIntLiteral ? WurstTypeInt.instance() : type;
}
}
}
} else if (parent instanceof SwitchCase) {
SwitchCase sc = (SwitchCase) parent;
SwitchStmt s = (SwitchStmt) sc.getParent().getParent();
Expand Down Expand Up @@ -110,6 +153,13 @@ public class AttrExprExpectedType {

private static WurstType expectedTypeSuperCall(SuperConstructorCall sc, Expr expr) {
ConstructorDef constr = (ConstructorDef) sc.getParent();
ConstructorDef selected = constr.attrSuperConstructor();
if (selected != null) {
int selectedIndex = SmallHelpers.superArgs(constr).indexOf(expr);
if (selectedIndex >= 0 && selectedIndex < selected.getParameters().size()) {
return selected.getParameters().get(selectedIndex).getTyp().attrTyp();
Comment thread
Frotty marked this conversation as resolved.
Outdated
}
}
ClassDef c = constr.attrNearestClassDef();
if (c == null) {
return WurstTypeUnknown.instance();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,17 @@ private ImClass createClass() {
OverrideUtils.addOverrideClosure(tr, superMethod, m, e);


ImExpr translated = e.getImplementation().imTranslateExpr(tr, impl);
ImExpr translated;
boolean propagatesExpectedType = e.getImplementation() instanceof ExprIfElse
|| e.getImplementation() instanceof ExprUnary;
Comment thread
Frotty marked this conversation as resolved.
Outdated
if (propagatesExpectedType) {
translated = ExprTranslation.translateWithExpectedType(
e.getImplementation(), tr, impl, superMethod.attrReturnType());
} else {
translated = e.getImplementation().imTranslateExpr(tr, impl);
translated = ExprTranslation.wrapTranslation(e.getImplementation(), tr, translated,
e.getImplementation().attrTypRaw(), superMethod.attrReturnType());
}


if (e.getImplementation().attrTyp().isVoid()) {
Expand Down
Loading
Loading