1
0
mirror of https://gitlab.com/camelot/kickc.git synced 2024-11-22 16:33:48 +00:00

Added proper error message on unknown struct memeber. Closes #638

This commit is contained in:
jespergravgaard 2021-03-03 22:24:18 +01:00
parent ad2bb7cced
commit 56fe16e753
4 changed files with 27 additions and 6 deletions

View File

@ -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());

View File

@ -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");

View File

@ -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;
}