diff --git a/src/main/java/dk/camelot64/kickc/passes/PassNAssertStructMembers.java b/src/main/java/dk/camelot64/kickc/passes/PassNAssertStructMembers.java index 367ca88ad..161a093c4 100644 --- a/src/main/java/dk/camelot64/kickc/passes/PassNAssertStructMembers.java +++ b/src/main/java/dk/camelot64/kickc/passes/PassNAssertStructMembers.java @@ -7,6 +7,7 @@ import dk.camelot64.kickc.model.symbols.StructDefinition; import dk.camelot64.kickc.model.symbols.Variable; import dk.camelot64.kickc.model.types.SymbolType; import dk.camelot64.kickc.model.types.SymbolTypeInference; +import dk.camelot64.kickc.model.types.SymbolTypePointer; import dk.camelot64.kickc.model.types.SymbolTypeStruct; import dk.camelot64.kickc.model.values.StructMemberRef; @@ -32,6 +33,11 @@ public class PassNAssertStructMembers extends Pass2SsaOptimization { if(member==null) { throw new CompileError("Unknown struct member "+structMemberRef.getMemberName()+" in struct "+structType.getTypeName(), currentStmt); } + } else { + if(type instanceof SymbolTypePointer) + throw new CompileError("member '"+structMemberRef.getMemberName()+"' reference type '"+type.getTypeBaseName()+"' is a pointer; did you mean to use '->'?", currentStmt); + else + throw new CompileError("member '"+structMemberRef.getMemberName()+"' reference operator '.'/'->' applied to a non-struct", currentStmt); } } }); diff --git a/src/test/java/dk/camelot64/kickc/test/TestProgramsFast.java b/src/test/java/dk/camelot64/kickc/test/TestProgramsFast.java index d2bb753ba..377e393b6 100644 --- a/src/test/java/dk/camelot64/kickc/test/TestProgramsFast.java +++ b/src/test/java/dk/camelot64/kickc/test/TestProgramsFast.java @@ -2267,6 +2267,11 @@ public class TestProgramsFast extends TestPrograms { compileAndCompare("weeip-checksum.c"); } + @Test + public void testWeeipBbbsList() throws IOException { + compileAndCompare("weeip-bbslist.c"); + } + @Test public void testUnion8() throws IOException { compileAndCompare("union-8.c"); diff --git a/src/test/kc/weeip-bbslist.c b/src/test/kc/weeip-bbslist.c new file mode 100644 index 000000000..52eef136a --- /dev/null +++ b/src/test/kc/weeip-bbslist.c @@ -0,0 +1,49 @@ +// Test initialization of array of struct with char* elements + +#include +#include + +struct bbs { + char *name; + char *host_name; + unsigned int port_number; +}; + +#define NULL 0 + +const struct bbs bbs_list[27]= + { + {"Boar's Head","byob.hopto.org",64128}, + {"RapidFire","rapidfire.hopto.org",64128}, + {"Antidote by Triad","antidote.hopto.org",64128}, + {"Wizards's Realm", "wizardsrealm.c64bbs.org", 23}, + {"The Hidden", "the-hidden.hopto.org", 64128}, + {"Eaglewing BBS", "eagelbird.ddns.net", 6400}, + {"Scorps Portal", "scorp.us.to", 23}, + {"My C=ult BBS", "maraud.dynalias.com", 6400}, + {"Commodore Image", "cib.dyndns.org", 6400}, + {"64 Vintag Remic", "64vintageremixbbs.dyndns.org", 6400}, + {"Jamming Signal", "bbs.jammingsignal.com", 23}, + {"Centronian BBS", "centronian.servebeer.com", 6400}, + {"Anrchy Undergrnd", "aubbs.dyndns.org", 2300}, + {"The Oasis BBS", "oasisbbs.hopto.org", 6400}, + {"The Disk Box", "bbs.thediskbox.com", 6400}, + {"Cottonwood", "cottonwoodbbs.dyndns.org", 6502}, + {"Wrong Number ][", "cib.dyndns.org", 6404}, + {"RabidFire", "rapidfire.hopto.org", 64128}, + {"Mad World", "madworld.bounceme.net", 6400}, + {"Citadel 64", "bbs.thejlab.com", 6400}, + {"Hotwire BBS", "hotwirebbs.zapto.org", 6502}, + {"Endless Chaos", "endlesschaos.dyndns.org", 6400}, + {"Borderline", "borderlinebbs.dyndns.org", 6400}, + {"RAVELOUTION","raveolution.hopto.org",64128}, + {"The Edge BBS","theedgebbs.dyndns.org",1541}, + {"PGS Test","F96NG92-L.fritz.box",64128}, + {NULL,NULL,0} + }; + +void main() { + VICII->MEMORY = 0x17; + for(struct bbs * bbs = bbs_list; bbs->name; bbs++) + printf("%s %s %u\n", bbs->name, bbs->host_name, bbs->port_number); +}