Skip to content

[BUGFIX] Solve two bugs with string interpolation#407

Open
NotHyper-474 wants to merge 1 commit into
FunkinCrew:experimentalfrom
NotHyper-474:fix/string-interp-bugs
Open

[BUGFIX] Solve two bugs with string interpolation#407
NotHyper-474 wants to merge 1 commit into
FunkinCrew:experimentalfrom
NotHyper-474:fix/string-interp-bugs

Conversation

@NotHyper-474
Copy link
Copy Markdown
Collaborator

@NotHyper-474 NotHyper-474 commented May 10, 2026

Overview

  • Quote escapes now works properly inside ${...} expressions.
  • Identifiers in expressions like $a$b now get correctly interpreted as strings if those happen to be numbers.
Updated Assert Script

import funkin.modding.module.Module;
import funkin.modding.module.ModuleHandler;

class StrInterpAssert extends Module
{
  override function onCreate(_)
  {
    var x = 10;

    function test(s:String)
    {
      return s;
    }

    var ease:String = 'cubic';
    var easeDir:String = 'Out';

    var a = 1;
    var b = 2;

    assertStr("$a$b", '$a$b', "12");
    assertStr("${'$a$b'}", '${'$a$b'}', "12");
    assertStr("$ease$easeDir", '$ease$easeDir', "cubicOut");
    assertStr("$ease${easeDir}", '$ease${easeDir}', "cubicOut");
    assertStr("${ease}$easeDir", '${ease}$easeDir', "cubicOut");
    assertStr("${'{'}", '${'{'}', "{");
    assertStr("${'}'}", '${'}'}', "}");
    assertStr("${'{}'}", '${'{}'}', "{}");
    assertStr("${\"{\"}", '${"{"}', "{");
    assertStr("${test('string')}", '${test('string')}', "string");
    assertStr("${test('string ${0}')}", '${test('string ${0}')}', "string 0");
    assertStr("$x and ${test('$x') + '10'}", '$x and ${test('$x') + ' 10'}', "10 and 10 10");
    assertStr("$$", '$$', "$");
    assertStr("$$$x", '$$$x', "$10");
    assertStr("$$$x ", '$$$x ', "$10 ");
    assertStr("$-=", '$-=', "$-=");
    assertStr("$x ", '$x ', "10 ");
    assertStr("$x", '$x', "10");
    assertStr("$", '$', "$");
    assertStr("${'Escaped 'single quoted' string.'}", '${'Escaped \'single quoted\' string.'}', "Escaped 'single quoted' string.");
    assertStr("$ x", '$ x', "$ x");
    assertStr("$x + 3 is ${x + 3}", '$x + 3 is ${x + 3}', "10 + 3 is 13");
  }

  function assertStr(literal:String, str:String, ass:String)
  {
    if (literal?.length == 0) throw 'Forgot "literal"!';
    if (str?.length == 0) throw 'Forgot "str"!';
    if (ass?.length == 0) throw 'Forgot "ass"!';
    trace('ASSERT: ("' + literal + '" -> "' + ass + '"), RESULT: "' + str + ((str == ass) ? '" (SUCCESS)' : '" (FAIL)'));
  }
}

The strings in the script look like this after parsed (some of these traces come from the ${...} parts):
expr-output

Quote escapes now works properly inside `${...}` expressions.
Improved string enforcing within some cases
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant