mirror of
https://github.com/KAMKEEL/CustomNPC-Plus.git
synced 2026-11-13 05:27:37 +00:00
Fix expression typing gate to route JS function/lambda expressions into ExpressionParser
Problem:
- function(act){...} expressions not reaching ExpressionParser
- resolveExpressionType only checked containsOperators() or startsWith("(")
- Function expressions went through simple resolver and returned null type
Solution:
- Added looksLikeFunctionOrLambda helper (lines 4766-4773) to detect:
* JS functions: function(...)
* Arrow functions: =>
* Java lambdas: ->
- Updated gate condition at line 4144 to route these into ExpressionParser
- Function expressions now reach ExpressionTypeResolver.resolveJSFunctionType
Impact:
- SAM typing now works in pass-2 when expected type is known
- Fixes schedule("TpGainAction", function(act){...}) argument typing
- Enables proper overload resolution for function/lambda parameters
This commit is contained in:
1 parent
ba7e4cc3b2
commit
6fc0bf4d6b
1 file changed
+22
-5
@@ -4138,11 +4138,12 @@ public class ScriptDocument {
|
||||
return null;
|
||||
}
|
||||
|
||||
// Check if expression contains operators - if so, use the full expression resolver
|
||||
// Handle cast expressions: (Type)expr, ((Type)expr).method(), etc.
|
||||
if (containsOperators(expr) || expr.startsWith("(")) {
|
||||
return resolveExpressionWithParserAPI(expr, position);
|
||||
}
|
||||
// Check if expression contains operators - if so, use the full expression resolver
|
||||
// Handle cast expressions: (Type)expr, ((Type)expr).method(), etc.
|
||||
// Also route JS function expressions and arrow lambdas through the parser
|
||||
if (containsOperators(expr) || expr.startsWith("(") || looksLikeFunctionOrLambda(expr)) {
|
||||
return resolveExpressionWithParserAPI(expr, position);
|
||||
}
|
||||
|
||||
// Invalid expressions starting with brackets
|
||||
if (expr.startsWith("[") || expr.startsWith("]")) {
|
||||
@@ -4755,6 +4756,22 @@ public class ScriptDocument {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if an expression looks like a JS function or arrow lambda.
|
||||
* This is a fast heuristic to detect:
|
||||
* - JS function expressions: function(...) {}
|
||||
* - Arrow lambdas: (...) => ...
|
||||
* These need to be routed through the parser for proper SAM typing.
|
||||
*/
|
||||
private boolean looksLikeFunctionOrLambda(String expr) {
|
||||
if (expr == null || expr.isEmpty()) return false;
|
||||
String trimmed = expr.trim();
|
||||
if (trimmed.startsWith("function")) return true;
|
||||
if (trimmed.contains("=>")) return true;
|
||||
if (trimmed.contains("->")) return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Resolve an expression that contains operators or casts using the full expression parser.
|
||||
* This handles all Java operators with proper precedence and type promotion rules.
|
||||
|
||||
Reference in new issue
Block a user