Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Crash on ambiguous string interpolation expression #11402

Closed
triplefox opened this issue Nov 21, 2023 · 3 comments
Closed

Crash on ambiguous string interpolation expression #11402

triplefox opened this issue Nov 21, 2023 · 3 comments
Assignees

Comments

@triplefox
Copy link

The following code crashes the compiler when run with "haxe -x Bug_2023Nov21.hx" (Tested on Haxe 4.3.3/unix and 4.3.1/unix):

class Bug_2023Nov21 {
  static function test() : String {
    var cells = [1,2,3];
    var ans = "";
    ans += '${cells.length} cell${if (cells.length == 1) {return "";} else {return "s";}}.\n';
    return ans;
  }
  static function main() {
    trace(test());
  }

}

File "src/optimization/analyzerTexprTransformer.ml", line 123, characters 18-25 Called from file "src/optimization/analyzerTexprTransformer.ml", line 123, characters 11-25 Called from file "src/optimization/analyzerTexprTransformer.ml", line 184, characters 13-24 Called from file "src/optimization/analyzerTexprTransformer.ml", line 285, characters 15-25 Called from file "src/optimization/analyzerTexprTransformer.ml", line 245, characters 11-47 Called from file "src/optimization/analyzerTexprTransformer.ml", line 208, characters 38-55 Called from file "list.ml", line 121, characters 24-34 Called from file "src/optimization/analyzerTexprTransformer.ml", line 204, characters 18-238 Called from file "src/optimization/analyzerTexprTransformer.ml", line 121, characters 24-53 Called from file "src/optimization/analyzerTexprTransformer.ml", line 184, characters 13-24 Called from file "src/optimization/analyzerTexprTransformer.ml", line 364, characters 16-27 Called from file "src/optimization/analyzerTexprTransformer.ml", line 632, characters 14-32 Called from file "src/optimization/analyzerTexprTransformer.ml", line 660, characters 15-39 Called from file "src/optimization/analyzerTexprTransformer.ml", line 668, characters 23-47 Called from file "src/optimization/analyzer.ml", line 951, characters 10-13 Called from file "src/optimization/analyzer.ml", line 995, characters 2-106 Called from file "src/optimization/analyzer.ml", line 1059, characters 25-37 Called from file "src/optimization/analyzer.ml", line 1097, characters 4-22 Called from file "src/optimization/analyzer.ml", line 1112, characters 2-30 Called from file "list.ml", line 110, characters 12-15 Called from file "src/optimization/analyzer.ml", line 1122, characters 2-53 File "src/core/globals.ml", line 156, characters 1-7: Assertion failed

The string interpolation is generally considered an error by the compiler(and there are plenty of ways to rewrite it in a way the compiler agrees with), but this one fails in different ways when I move it around to slightly different contexts.

@Simn
Copy link
Member

Simn commented Nov 21, 2023

Nice one! Can be reduced quite a bit:

class Main {
	static function test() {
		var ans = Std.string(return "") + "";
	}

	static function main() {
		test();
	}
}

The analyzer doesn't deal with the unreachable block in value binops correctly.

I'm not sure why the original code should be an error though.

@Simn Simn self-assigned this Nov 21, 2023
@Simn Simn closed this as completed in 7653f68 Nov 22, 2023
@kLabz kLabz added this to the 4.3 Hotfix milestone Nov 22, 2023
@kLabz
Copy link
Contributor

kLabz commented Nov 22, 2023

Can repro on 4.3.x too

@Simn
Copy link
Member

Simn commented Nov 22, 2023

Yeah, I already added the commit to #11394.

0b1kn00b pushed a commit to 0b1kn00b/haxe that referenced this issue Jan 25, 2024
@kLabz kLabz removed this from the 4.3 Hotfix milestone Feb 18, 2024
kLabz pushed a commit that referenced this issue Feb 18, 2024
kLabz pushed a commit that referenced this issue Mar 4, 2024
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

No branches or pull requests

3 participants