added wrong type in if clause
Some checks are pending
Gitea Actions Demo / Explore-Gitea-Actions (push) Waiting to run

This commit is contained in:
Bruder John 2024-06-21 18:06:49 +02:00
parent 7b41c45cd5
commit 5bf9a4fc73
4 changed files with 42 additions and 3 deletions

View File

@ -175,7 +175,7 @@ public class SemanticAnalyzer implements SemanticVisitor {
@Override
public TypeCheckResult analyze(IfStatementNode toCheck) {
return null;
return new TypeCheckResult(true, null);
}
@Override
@ -275,7 +275,7 @@ public class SemanticAnalyzer implements SemanticVisitor {
@Override
public TypeCheckResult analyze(IfElseStatementNode toCheck) {
return null;
return new TypeCheckResult(true, null);
}
@Override

View File

@ -49,6 +49,7 @@ public class EndToTAST {
ASTNode tast = SemanticAnalyzer.generateTast(abstractSyntaxTree);
assertEquals(SemanticAnalyzer.errors.size(), 0);
assertNotNull(tast);
@ -254,4 +255,28 @@ public class EndToTAST {
}
@Test
public void wrongTypeInIfClause(){
CharStream codeCharStream = null;
try {
codeCharStream = CharStreams.fromPath(Paths.get("src/test/resources/semantic/endToTAST/WrongIfClause.java"));
} catch (IOException e) {
throw new RuntimeException(e);
}
SimpleJavaLexer lexer = new SimpleJavaLexer(codeCharStream);
CommonTokenStream tokenStream = new CommonTokenStream(lexer);
SimpleJavaParser parser = new SimpleJavaParser(tokenStream);
ParseTree parseTree = parser.program();
ASTBuilder astBuilder = new ASTBuilder();
ProgramNode abstractSyntaxTree = (ProgramNode) astBuilder.visit(parseTree);
ASTNode tast = SemanticAnalyzer.generateTast(abstractSyntaxTree);
assertFalse(SemanticAnalyzer.errors.isEmpty());
}
}

View File

@ -2,10 +2,17 @@ public class Example {
public int a;
public static int testMethod(int b){
public static int testMethod(int b, boolean bo){
a = b;
if(bo){
}
return a;
}
public static void testMethod(int b){
}
}

View File

@ -0,0 +1,7 @@
public class Example {
public static void testMethod(int x){
}
}