Skip to content

Commit

Permalink
[22] VerifyError when String template expression is used as part of c…
Browse files Browse the repository at this point in the history
…ondition #2121 (#2126)

* fix for #2121

* additional tests added
  • Loading branch information
mpalat committed Mar 11, 2024
1 parent 25aa17f commit ec02061
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@ public void generateCode(BlockScope currentScope, CodeStream codeStream, boolean
codeStream.checkcast(this.invocation.binding.returnType);
if (!valueRequired) {
codeStream.pop();
} else {
codeStream.generateImplicitConversion(this.implicitConversion);
}
}
@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1908,4 +1908,72 @@ Description Width height() Area
\\{} plus \\{} equals \\{}
[10, 20, 30]""");
}
public void testIssue2121_01() {
runConformTest(
new String[] {
"X.java",
"""
interface TemplateProcessor extends java.lang.StringTemplate.Processor<Boolean, RuntimeException> {
Boolean process(StringTemplate st);
}

public class X {
public static void main(String argv[]) {
TemplateProcessor STR = st -> st.interpolate().equals("abc");
if (STR."abc") {
System.out.println("hello");
}
}
}
"""
},
"hello"
);
}
public void testIssue2121_02() {
runConformTest(
new String[] {
"X.java",
"""
interface TemplateProcessor extends java.lang.StringTemplate.Processor<Boolean, RuntimeException> {
Boolean process(StringTemplate st);
}

public class X {
public static void main(String argv[]) {
TemplateProcessor STR = st -> st.interpolate().equals("abc");
int i = 0;
while ((STR."abc") && i < 1) {
i++;
System.out.println("hello");
}
}
}
"""
},
"hello"
);
}
public void testIssue2121_03() {
runConformTest(
new String[] {
"X.java",
"""
interface TemplateProcessor extends java.lang.StringTemplate.Processor<Boolean, RuntimeException> {
Boolean process(StringTemplate st);
}

public class X {
public static void main(String argv[]) {
TemplateProcessor STR = st -> st.interpolate().equals("abc");
for ( int i = 0; (STR."abc") && i < 1; i++) {
System.out.println("hello");
}
}
}
"""
},
"hello"
);
}
}

0 comments on commit ec02061

Please sign in to comment.