Fix validation exception when calling roFunction#1588
Conversation
There was a problem hiding this comment.
This one solves the original problem!
However, it reveals a new crash when you have a pattern like this:
function calc(a as dynamic, b as dynamic, op as string) as dynamic
op = getOperation(op)
return op(1, 2)
end function
function getOperation(name as string) as object
return {
"sum": function(a as dynamic, b as dynamic) as dynamic
return a + b
end function
"sub": function(a as dynamic, b as dynamic) as dynamic
return a - b
end function
"mul": function(a as dynamic, b as dynamic) as dynamic
return a * b
end function
"div": function(a as dynamic, b as dynamic) as dynamic
return a / b
end function
}
end function[11:56:29:165 AM] Validating project
[11:56:29:212 AM] Error when calling plugin BscPlugin.onScopeValidate: TypeError: this.outerType.getTarget is not a function
at Object.get (/Users/lse16/dev/brighterscript-test-bench/node_modules/brighterscript/src/types/ReferenceType.ts:397:101)
at isVoidType (/Users/lse16/dev/brighterscript-test-bench/node_modules/brighterscript/src/astUtils/reflection.ts:410:19)
at ScopeValidator.validateReturnStatement (/Users/lse16/dev/brighterscript-test-bench/node_modules/brighterscript/src/bscPlugin/validation/ScopeValidator.ts:673:47)
at /Users/lse16/dev/brighterscript-test-bench/node_modules/brighterscript/src/bscPlugin/validation/ScopeValidator.ts:205:34
at ScopeValidator.addValidationKindMetric (/Users/lse16/dev/brighterscript-test-bench/node_modules/brighterscript/src/bscPlugin/validation/ScopeValidator.ts:332:9)
at Object.ReturnStatement (/Users/lse16/dev/brighterscript-test-bench/node_modules/brighterscript/src/bscPlugin/validation/ScopeValidator.ts:204:30)
at /Users/lse16/dev/brighterscript-test-bench/node_modules/brighterscript/src/astUtils/visitors.ts:222:51
at walk (/Users/lse16/dev/brighterscript-test-bench/node_modules/brighterscript/src/astUtils/visitors.ts:54:23)
at walkArray (/Users/lse16/dev/brighterscript-test-bench/node_modules/brighterscript/src/astUtils/visitors.ts:119:29)
at Block.walk (/Users/lse16/dev/brighterscript-test-bench/node_modules/brighterscript/src/parser/Statement.ts:467:22)
at walk (/Users/lse16/dev/brighterscript-test-bench/node_modules/brighterscript/src/astUtils/visitors.ts:93:13)
at FunctionExpression.walk (/Users/lse16/dev/brighterscript-test-bench/node_modules/brighterscript/src/parser/Expression.ts:414:6)
at walk (/Users/lse16/dev/brighterscript-test-bench/node_modules/brighterscript/src/astUtils/visitors.ts:93:13)
at FunctionStatement.walk (/Users/lse16/dev/brighterscript-test-bench/node_modules/brighterscript/src/parser/Statement.ts:654:17)
at /Users/lse16/dev/brighterscript-test-bench/node_modules/brighterscript/src/bscPlugin/validation/ScopeValidator.ts:312:29
at Scope.enumerateOwnFiles (/Users/lse16/dev/brighterscript-test-bench/node_modules/brighterscript/src/Scope.ts:706:17)
[11:56:29:214 AM] Validating project finished. (48.761ms)
actualReturnType is a TypePropertyReferenceType which lacks getTarget().
|
Oh interesting! I don't get the crash if |
|
@luis-j-soares Yes, I do! weird! |
|
@luis-j-soares I was able to reproduce, and I think this will fix that issue now |
|
|
||
| export function isCallableType(target): target is BaseFunctionType { | ||
| return isFunctionTypeLike(target) || isTypedFunctionType(target) || (isDynamicType(target) && !isAnyReferenceType(target)); | ||
| return isFunctionTypeLike(target) || isTypedFunctionType(target) || isObjectType(target) || (isDynamicType(target) && !isAnyReferenceType(target)); |
There was a problem hiding this comment.
object is callable , because roFunction is an object. sheesh
|
Hey there! I just built a new temporary npm package based on 3f32e85. You can download it here or install it by running the following command: npm install https://github.com/rokucommunity/brighterscript/releases/download/v0.0.0-packages/brighterscript-1.0.0-alpha.48-fix-return-validation-on-roFunction.20251103153805.tgz |
luis-j-soares
left a comment
There was a problem hiding this comment.
Tentatively approving since it's fixing all of the compiler errors I've seen, although the proxy code is still quite unknown to me. 😅
|
Hey there! I just built a new temporary npm package based on 6700b81. You can download it here or install it by running the following command: npm install https://github.com/rokucommunity/brighterscript/releases/download/v0.0.0-packages/brighterscript-1.0.0-alpha.48-fix-return-validation-on-roFunction.20251104175005.tgz |
Fixes #1587
The return type of a
roFunctionwas undefined. This PR changes it so if we're calling a variable typed asroFunctionwe getdynamic(just like as if we're calling something typed asfunction)