Skip to content

Commit 6dd35e1

Browse files
gh-187: Make TYPE-only assignment error on type conflict.
Closes #187
1 parent 3f5771b commit 6dd35e1

2 files changed

Lines changed: 14 additions & 0 deletions

File tree

src/interpreter.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2630,7 +2630,19 @@ static ExecResult exec_stmt(Interpreter* interp, Stmt* stmt, Env* env, LabelMap*
26302630
decl_env = env->parent;
26312631
}
26322632
env_define(decl_env, stmt->as.decl.name, stmt->as.decl.decl_type);
2633+
return make_ok(value_null());
2634+
}
2635+
2636+
/* If the symbol already exists, the declared static type must match.
2637+
Per specification, redeclaring with a different static type is
2638+
a runtime error rather than a no-op. */
2639+
if (existing->decl_type != stmt->as.decl.decl_type) {
2640+
char buf[128];
2641+
snprintf(buf, sizeof(buf), "Type mismatch: expected %s but got %s",
2642+
decl_type_name(existing->decl_type), decl_type_name(stmt->as.decl.decl_type));
2643+
return make_error(buf, stmt->line, stmt->column);
26332644
}
2645+
26342646
return make_ok(value_null());
26352647
}
26362648

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
INT n = 0d0
2+
BOOL n

0 commit comments

Comments
 (0)