diff --git a/src/main/java/dk/camelot64/kickc/model/types/SymbolTypeInference.java b/src/main/java/dk/camelot64/kickc/model/types/SymbolTypeInference.java index b91885986..dc662b859 100644 --- a/src/main/java/dk/camelot64/kickc/model/types/SymbolTypeInference.java +++ b/src/main/java/dk/camelot64/kickc/model/types/SymbolTypeInference.java @@ -43,7 +43,7 @@ public class SymbolTypeInference { SymbolType rightType = inferType(symbols, constBin.getRight()); return constBin.getOperator().inferType(leftType, rightType); } else if(rValue instanceof ValueList) { - return SymbolType.VAR; + return SymbolType.VAR; } else if(rValue instanceof PointerDereference) { SymbolType pointerType = inferType(symbols, ((PointerDereference) rValue).getPointer()); if(pointerType instanceof SymbolTypePointer) { @@ -105,6 +105,8 @@ public class SymbolTypeInference { String typeName = ((SymbolTypeStruct) structType).getStructTypeName(); StructDefinition structDefinition = symbols.getLocalStructDefinition(typeName); Variable structMember = structDefinition.getLocalVar(structMemberRef.getMemberName()); + if(structMember == null) + throw new CompileError("Unknown struct member " + structMemberRef.getMemberName() + " in struct " + structType.getTypeName()); return structMember.getType(); } else { throw new CompileError("Dot applied to non-struct "+ structMemberRef.getStruct().toString()); diff --git a/src/test/java/dk/camelot64/kickc/test/TestPrograms.java b/src/test/java/dk/camelot64/kickc/test/TestPrograms.java index 536f7a2e7..4143e59fa 100644 --- a/src/test/java/dk/camelot64/kickc/test/TestPrograms.java +++ b/src/test/java/dk/camelot64/kickc/test/TestPrograms.java @@ -2073,11 +2073,6 @@ public class TestPrograms { } */ - @Test - public void testStructError6() throws IOException, URISyntaxException { - assertError("struct-error-6.c", "Value list cannot initialize type"); - } - @Test public void testStructPtr34() throws IOException, URISyntaxException { compileAndCompare("struct-ptr-34.c"); @@ -2254,6 +2249,17 @@ public class TestPrograms { compileAndCompare("struct-ptr-0.c"); } + @Test + public void testStructError7() throws IOException, URISyntaxException { + assertError("struct-err-7.c", "Unknown struct member"); + } + + @Test + public void testStructError6() throws IOException, URISyntaxException { + assertError("struct-err-6.c", "Value list cannot initialize type"); + } + + @Test public void testStructError5() throws IOException, URISyntaxException { assertError("struct-err-5.c", "Unknown struct member"); diff --git a/src/test/kc/struct-error-6.c b/src/test/kc/struct-err-6.c similarity index 100% rename from src/test/kc/struct-error-6.c rename to src/test/kc/struct-err-6.c diff --git a/src/test/kc/struct-err-7.c b/src/test/kc/struct-err-7.c new file mode 100644 index 000000000..800a82581 --- /dev/null +++ b/src/test/kc/struct-err-7.c @@ -0,0 +1,13 @@ +// Example of error referencing unknown struct member in rvalue + +struct Person { + char id; + char age; +}; + +void main() { + struct Person* per; + int x = per->qwe; +} + +