mirror of
https://gitlab.com/camelot/kickc.git
synced 2024-12-22 21:29:50 +00:00
Added proper error message on unknown struct memeber. Closes #638
This commit is contained in:
parent
ad2bb7cced
commit
56fe16e753
@ -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());
|
||||
|
@ -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");
|
||||
|
13
src/test/kc/struct-err-7.c
Normal file
13
src/test/kc/struct-err-7.c
Normal 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;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user