summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTing-Wei Lan <lantw44@gmail.com>2015-12-09 21:44:43 +0800
committerTing-Wei Lan <lantw44@gmail.com>2015-12-09 21:44:43 +0800
commit21e4bdf1d0c2772d37672dc7b92b3c924e121968 (patch)
tree4c2c4e8d4832ccbd095c1a3fdb0c3129e42e4df5
parent2389c7b3b3e8d3621342d2122f4299a5a1082cec (diff)
downloadcompiler2015-21e4bdf1d0c2772d37672dc7b92b3c924e121968.tar
compiler2015-21e4bdf1d0c2772d37672dc7b92b3c924e121968.tar.gz
compiler2015-21e4bdf1d0c2772d37672dc7b92b3c924e121968.tar.bz2
compiler2015-21e4bdf1d0c2772d37672dc7b92b3c924e121968.tar.lz
compiler2015-21e4bdf1d0c2772d37672dc7b92b3c924e121968.tar.xz
compiler2015-21e4bdf1d0c2772d37672dc7b92b3c924e121968.tar.zst
compiler2015-21e4bdf1d0c2772d37672dc7b92b3c924e121968.zip
Scalars cannot be used as arrays and arrays cannot be used as scalars
-rw-r--r--src/semantic-analysis.c10
1 files changed, 10 insertions, 0 deletions
diff --git a/src/semantic-analysis.c b/src/semantic-analysis.c
index 7d892cc..c45e1a3 100644
--- a/src/semantic-analysis.c
+++ b/src/semantic-analysis.c
@@ -409,9 +409,19 @@ static bool check_var_ref(CcmmcAst *ref, CcmmcSymbolTable *table)
switch (ref->value_id.kind) {
case CCMMC_KIND_ID_NORMAL:
ref->type_value = symbol->type.type_base;
+ if (!ccmmc_symbol_is_scalar(symbol)) {
+ fprintf(stderr, ERROR("ID `%s' is not a scalar"),
+ ref->line_number, ref->value_id.name);
+ return true;
+ }
return false;
case CCMMC_KIND_ID_ARRAY:
ref->type_value = symbol->type.type_base;
+ if (!ccmmc_symbol_is_array(symbol)) {
+ fprintf(stderr, ERROR("ID `%s' is not an array"),
+ ref->line_number, ref->value_id.name);
+ return true;
+ }
return check_array_ref(ref, table, symbol);
case CCMMC_KIND_ID_WITH_INIT:
default: