Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions src/frontend/Typechecker.ml
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,10 @@ let verify_name_fresh_var loc tenv name =
if Utils.is_unnormalized_distribution name then
Semantic_error.ident_has_unnormalized_suffix loc name |> error
else if
Env.mem tenv name
&& not (Stan_math_signatures.is_stan_math_function_name name)
List.exists (Env.find tenv name) ~f:(function
| {kind= `StanMath; _} ->
false (* user variables can shadow library names *)
| _ -> true )
then Semantic_error.ident_in_use loc name |> error

(** verify that the variable being declared is previous unused.
Expand Down
5 changes: 5 additions & 0 deletions test/integration/bad/lang/reused_name.stan
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
generated quantities {
vector[3] e;
// e is selected because it is also a Stan-math function 'e()'
vector[3] e;
}
11 changes: 11 additions & 0 deletions test/integration/bad/lang/stanc.expected
Original file line number Diff line number Diff line change
Expand Up @@ -696,6 +696,17 @@ Expected an expression inside "[" and "]" but found a statement. Indexing should
var[1 + i]
not
var[for (n in 1:N) ...]
$ ../../../../../install/default/bin/stanc reused_name.stan
Semantic error in 'reused_name.stan', line 4, column 14 to column 15:
-------------------------------------------------
2: vector[3] e;
3: // e is selected because it is also a Stan-math function 'e()'
4: vector[3] e;
^
5: }
-------------------------------------------------

Identifier 'e' is already in use.
$ ../../../../../install/default/bin/stanc unterminated_comment.stan
Syntax error in 'unterminated_comment.stan', line 4, column -1, lexing error:
-------------------------------------------------
Expand Down