feat: changes in Grammar and Parser so typeless Recs get recognised
Some checks failed
Build and Test with Maven / Build-and-test-with-Maven (push) Has been cancelled
Some checks failed
Build and Test with Maven / Build-and-test-with-Maven (push) Has been cancelled
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
|
||||
: typeType recordStructurePattern identifier?
|
||||
//| recordStructurePattern identifier?
|
||||
;
|
||||
|
||||
typePattern
|
||||
: variableModifier* typeType identifier
|
||||
| variableModifier* identifier
|
||||
;
|
||||
|
||||
recordStructurePattern
|
||||
@ -717,10 +719,10 @@ switchLabeledRule
|
||||
;
|
||||
|
||||
switchLabelCase
|
||||
: CASE expressionList (ARROW | COLON) #labeledRuleExprList
|
||||
| CASE NULL_LITERAL (ARROW | COLON) #labeledRuleNull
|
||||
: CASE NULL_LITERAL (ARROW | COLON) #labeledRuleNull
|
||||
| CASE pattern (ARROW | COLON) #labeledRulePattern
|
||||
| DEFAULT (ARROW | COLON) #labeledRuleDefault
|
||||
| CASE expressionList (ARROW | COLON) #labeledRuleExprList
|
||||
;
|
||||
|
||||
// Java20
|
||||
|
@ -457,7 +457,7 @@ public class StatementGenerator {
|
||||
case TPatternContext tPattern:
|
||||
TypePatternContext typePattern = tPattern.typePattern();
|
||||
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);
|
||||
return new FormalParameter(text, type, typePattern.getStart());
|
||||
case RPatternContext rPattern:
|
||||
|
@ -673,6 +673,15 @@ public class TestComplete {
|
||||
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")
|
||||
@Test
|
||||
public void testSwitch2() throws Exception {
|
||||
|
Loading…
Reference in New Issue
Block a user