forked from JavaTX/JavaCompilerCore
feat: changes in Grammar and Parser so typeless Recs get recognised
This commit is contained in:
parent
4880527d4d
commit
7650813bb7
17
resources/bytecode/javFiles/SwitchInfered.jav
Normal file
17
resources/bytecode/javFiles/SwitchInfered.jav
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
import java.lang.Integer;
|
||||||
|
import java.lang.Object;
|
||||||
|
import java.lang.Float;
|
||||||
|
|
||||||
|
public record Rec(Integer a, Object b) {}
|
||||||
|
|
||||||
|
public class SwitchInfered {
|
||||||
|
public main(o) {
|
||||||
|
return switch (o) {
|
||||||
|
case Rec(a, b) -> a + b;
|
||||||
|
case Rec(Integer a, Float b) -> a + 10;
|
||||||
|
case Rec(Integer a, Rec(Integer b, Integer c)) -> a + b + c;
|
||||||
|
case Integer i -> i;
|
||||||
|
default -> 0;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
@ -658,10 +658,12 @@ primaryPattern
|
|||||||
|
|
||||||
recordPattern
|
recordPattern
|
||||||
: typeType recordStructurePattern identifier?
|
: typeType recordStructurePattern identifier?
|
||||||
|
//| recordStructurePattern identifier?
|
||||||
;
|
;
|
||||||
|
|
||||||
typePattern
|
typePattern
|
||||||
: variableModifier* typeType identifier
|
: variableModifier* typeType identifier
|
||||||
|
| variableModifier* identifier
|
||||||
;
|
;
|
||||||
|
|
||||||
recordStructurePattern
|
recordStructurePattern
|
||||||
@ -717,10 +719,10 @@ switchLabeledRule
|
|||||||
;
|
;
|
||||||
|
|
||||||
switchLabelCase
|
switchLabelCase
|
||||||
: CASE expressionList (ARROW | COLON) #labeledRuleExprList
|
: CASE NULL_LITERAL (ARROW | COLON) #labeledRuleNull
|
||||||
| CASE NULL_LITERAL (ARROW | COLON) #labeledRuleNull
|
|
||||||
| CASE pattern (ARROW | COLON) #labeledRulePattern
|
| CASE pattern (ARROW | COLON) #labeledRulePattern
|
||||||
| DEFAULT (ARROW | COLON) #labeledRuleDefault
|
| DEFAULT (ARROW | COLON) #labeledRuleDefault
|
||||||
|
| CASE expressionList (ARROW | COLON) #labeledRuleExprList
|
||||||
;
|
;
|
||||||
|
|
||||||
// Java20
|
// Java20
|
||||||
|
@ -457,7 +457,7 @@ public class StatementGenerator {
|
|||||||
case TPatternContext tPattern:
|
case TPatternContext tPattern:
|
||||||
TypePatternContext typePattern = tPattern.typePattern();
|
TypePatternContext typePattern = tPattern.typePattern();
|
||||||
var text = typePattern.identifier().getText();
|
var text = typePattern.identifier().getText();
|
||||||
var type = TypeGenerator.convert(typePattern.typeType(), reg, generics);
|
var type = typePattern.typeType() == null ? TypePlaceholder.fresh(typePattern.getStart()) : TypeGenerator.convert(typePattern.typeType(), reg, generics);
|
||||||
localVars.put(text, type);
|
localVars.put(text, type);
|
||||||
return new FormalParameter(text, type, typePattern.getStart());
|
return new FormalParameter(text, type, typePattern.getStart());
|
||||||
case RPatternContext rPattern:
|
case RPatternContext rPattern:
|
||||||
|
@ -673,6 +673,15 @@ public class TestComplete {
|
|||||||
assertEquals(swtch.invoke(instance, "Some string"), 0);
|
assertEquals(swtch.invoke(instance, "Some string"), 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Ignore("Not implemented")
|
||||||
|
@Test
|
||||||
|
public void testSwitchInfered() throws Exception {
|
||||||
|
var classFiles = generateClassFiles(new ByteArrayClassLoader(), "SwitchInfered.jav");
|
||||||
|
var clazz = classFiles.get("SwitchInfered");
|
||||||
|
var instance = clazz.getDeclaredConstructor().newInstance();
|
||||||
|
var swtch = clazz.getDeclaredMethod("main", Object.class);
|
||||||
|
}
|
||||||
|
|
||||||
@Ignore("Not implemented")
|
@Ignore("Not implemented")
|
||||||
@Test
|
@Test
|
||||||
public void testSwitch2() throws Exception {
|
public void testSwitch2() throws Exception {
|
||||||
|
Loading…
Reference in New Issue
Block a user