diff --git a/Compiler/src/Compiler.cpp b/Compiler/src/Compiler.cpp index a73490a0..cc605e87 100644 --- a/Compiler/src/Compiler.cpp +++ b/Compiler/src/Compiler.cpp @@ -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")); diff --git a/tests/conformance/stringinterp.lua b/tests/conformance/stringinterp.lua index a36becd4..e691ed96 100644 --- a/tests/conformance/stringinterp.lua +++ b/tests/conformance/stringinterp.lua @@ -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)")