From f7338a06b39782a46ae9c2280390a62b562a8c69 Mon Sep 17 00:00:00 2001 From: Bruder John Date: Tue, 2 Jul 2024 15:47:33 +0200 Subject: [PATCH] added MemberAccess to Assignable --- src/main/java/bytecode/MethodCodeGen.java | 2 +- src/main/java/semantic/SemanticAnalyzer.java | 3 +++ .../FieldOrParameterTypeMismatch.java | 10 ++++++++++ .../input/typedAstFeaturesTests/CorrectTest.java | 4 ++-- 4 files changed, 16 insertions(+), 3 deletions(-) create mode 100644 src/test/resources/input/typedAstExceptionsTests/FieldOrParameterTypeMismatch.java diff --git a/src/main/java/bytecode/MethodCodeGen.java b/src/main/java/bytecode/MethodCodeGen.java index a1776c6..0999f48 100644 --- a/src/main/java/bytecode/MethodCodeGen.java +++ b/src/main/java/bytecode/MethodCodeGen.java @@ -50,7 +50,7 @@ public class MethodCodeGen implements bytecode.visitor.MethodVisitor { @Override public void visit(ConstructorNode constructorNode) { methodVisitor = - classWriter.visitMethod(mapper.mapAccessTypeToOpcode(constructorNode.accessType), + classWriter.visitMethod(mapper.mapAccessTypeToOpcode(constructorNode.accesModifier), "", mapper.generateMethodDescriptor(new BaseType(TypeEnum.VOID), constructorNode.parameters), null, diff --git a/src/main/java/semantic/SemanticAnalyzer.java b/src/main/java/semantic/SemanticAnalyzer.java index c849067..110effd 100644 --- a/src/main/java/semantic/SemanticAnalyzer.java +++ b/src/main/java/semantic/SemanticAnalyzer.java @@ -246,6 +246,9 @@ public class SemanticAnalyzer implements SemanticVisitor { if (currentFields.get(toCheck.identifier) != null) { var type = currentFields.get(toCheck.identifier); toCheck.setTypeNode(type); + MemberAccessNode memberAccessNode = new MemberAccessNode(false); + memberAccessNode.identifiers.add(currentClass.identifier); + toCheck.memberAccess = memberAccessNode; return new TypeCheckResult(true, type); } else if (currentScope.getLocalVar(toCheck.identifier) != null) { var type = currentScope.getLocalVar(toCheck.identifier); diff --git a/src/test/resources/input/typedAstExceptionsTests/FieldOrParameterTypeMismatch.java b/src/test/resources/input/typedAstExceptionsTests/FieldOrParameterTypeMismatch.java new file mode 100644 index 0000000..0a9c17c --- /dev/null +++ b/src/test/resources/input/typedAstExceptionsTests/FieldOrParameterTypeMismatch.java @@ -0,0 +1,10 @@ +// @expected: TypeMismatchException +public class AllFeaturesClassExample { + int x; + + public boolean test(boolean x){ + return this.x; + } + +} + diff --git a/src/test/resources/input/typedAstFeaturesTests/CorrectTest.java b/src/test/resources/input/typedAstFeaturesTests/CorrectTest.java index c6d54fb..4d27ecd 100644 --- a/src/test/resources/input/typedAstFeaturesTests/CorrectTest.java +++ b/src/test/resources/input/typedAstFeaturesTests/CorrectTest.java @@ -2,8 +2,8 @@ public class AllFeaturesClassExample { int x; - public boolean test(boolean x){ - return x; + public void test(){ + x = 1; } }