Fix unreachable string & number branches in compileExprIndexExpr

This commit is contained in:
Will 2023-12-23 13:48:01 +00:00
parent e76802f2ce
commit ff3618bd2b

View file

@ -1978,11 +1978,10 @@ struct Compiler
{ {
RegScope rs(this); RegScope rs(this);
Constant cv = getConstant(expr->index); if (AstExprConstantNumber* number = expr->index->as<AstExprConstantNumber>();
number && number->value >= 1 && number->value <= 256 && double(int(number->value)) == number->value)
if (cv.type == Constant::Type_Number && cv.valueNumber >= 1 && cv.valueNumber <= 256 && double(int(cv.valueNumber)) == cv.valueNumber)
{ {
uint8_t i = uint8_t(int(cv.valueNumber) - 1); uint8_t i = uint8_t(int(number->value) - 1);
uint8_t rt = compileExprAuto(expr->expr, rs); uint8_t rt = compileExprAuto(expr->expr, rs);
@ -1990,9 +1989,9 @@ struct Compiler
bytecode.emitABC(LOP_GETTABLEN, target, rt, i); bytecode.emitABC(LOP_GETTABLEN, target, rt, i);
} }
else if (cv.type == Constant::Type_String) else if (AstExprConstantString* string = expr->index->as<AstExprConstantString>())
{ {
BytecodeBuilder::StringRef iname = sref(cv.getString()); BytecodeBuilder::StringRef iname = sref(string->value);
int32_t cid = bytecode.addConstantString(iname); int32_t cid = bytecode.addConstantString(iname);
if (cid < 0) if (cid < 0)
CompileError::raise(expr->location, "Exceeded constant limit; simplify the code to compile"); CompileError::raise(expr->location, "Exceeded constant limit; simplify the code to compile");