Skip to content

Commit 2d8b6a7

Browse files
committed
check type compatibility on cast
1 parent 43d8897 commit 2d8b6a7

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

kscr-core/Bytecode/Statement.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,10 @@ public virtual Stack Evaluate(RuntimeBase vm, Stack stack)
256256
stack[Default] = stack.This;
257257
break;
258258
case (StatementComponentType.Expression, BytecodeType.Cast):
259+
var targetType = vm.FindType(Arg)!;
260+
var currentType = stack[Default]!.Value!.Type;
261+
if (!targetType.CanHold(currentType))
262+
throw new InternalException($"Cannot cast {currentType} to {targetType}");
259263
// casting is implicitly evaluated by design
260264
break;
261265
case (StatementComponentType.Expression, BytecodeType.StmtIf):

0 commit comments

Comments
 (0)