Fix more complicated case

This commit is contained in:
Kampfkarren 2022-07-26 18:37:11 -07:00
parent 9ea7b44ab9
commit da716a6a76
2 changed files with 16 additions and 9 deletions

View file

@ -1509,18 +1509,19 @@ struct Compiler
if (formatStringIndex < 0)
CompileError::raise(expr->location, "Exceeded constant limit; simplify the code to compile");
bytecode.emitABC(LOP_LOADK, target, formatStringIndex, 0);
// INTERP CODE REVIEW: Why do I need this?
// If I don't, it emits `LOADK R1 K1` instead of `LOADK R2 K1`,
// and it gives the error "missing argument 2".
allocReg(expr, 1);
RegScope rs(this);
// bytecode.emitABC(LOP_LOADK, target, formatStringIndex, 0);
emitLoadK(target, formatStringIndex);
for (AstExpr* expression : expr->expressions)
compileExprAuto(expression, rs);
{
uint8_t reg = allocReg(expression, 1);
compileExpr(expression, reg, targetTemp);
}
BytecodeBuilder::StringRef formatMethod = sref(AstName("format"));

View file

@ -22,11 +22,17 @@ assertEq(`true = {true}`, "true = true")
-- -- assert(string.find(`{{ "nested braces!" }}`, "table"))
-- local name = "Luau"
-- assert(`Welcome to {
-- assertEq(`Welcome to {
-- name
-- }!` == "Welcome to Luau!")
-- assert(`Welcome to \
-- {name}!` == "Welcome to\nLuau!")
-- }!`, "Welcome to Luau!")
local nameNotConstantEvaluated = (function() return "Luau" end)()
assertEq(`Welcome to {nameNotConstantEvaluated}!`, "Welcome to Luau!")
-- assertEq(`This {local} does not exist`, "This nil does not exist")
-- assertEq(`Welcome to \
-- {name}!`, "Welcome to\nLuau!")
-- assert(`Escaped brace: \{} ({1})` == "Escaped brace: { (1)")
-- assert(`Backslash \ that escapes the space is not a part of the string... ({2})` == "Backslash that escapes the space is not a part of the string... (2)")