Skip to content

Commit 5bebf3b

Browse files
committed
switch to env.mem
1 parent c66d087 commit 5bebf3b

File tree

4 files changed

+32
-4
lines changed

4 files changed

+32
-4
lines changed

src/frontend/Typechecker.ml

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -405,12 +405,10 @@ let check_fn ~is_cond_dist loc tenv id es =
405405
List.mem known_families s ~equal:String.equal
406406
in
407407
match suffix with
408-
| ("lpmf" | "lumpf")
409-
when Utils.is_distribution_name (prefix ^ "_lpdf") ->
408+
| ("lpmf" | "lumpf") when Env.mem tenv (prefix ^ "_lpdf") ->
410409
Semantic_error.returning_fn_expected_wrong_dist_suffix_found loc
411410
(prefix, suffix)
412-
| ("lpdf" | "lumdf")
413-
when Utils.is_distribution_name (prefix ^ "_lpmf") ->
411+
| ("lpdf" | "lumdf") when Env.mem tenv (prefix ^ "_lpmf") ->
414412
Semantic_error.returning_fn_expected_wrong_dist_suffix_found loc
415413
(prefix, suffix)
416414
| _ ->
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
model {
2+
target += foo_lpdf(1);
3+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
data {
2+
int foo_lpmf;
3+
}
4+
model {
5+
target += foo_lpdf(1);
6+
}

test/integration/bad/missing_dist_suffix/stanc.expected

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,24 @@
1+
$ ../../../../../install/default/bin/stanc completely_undefined1.stan
2+
Semantic error in 'completely_undefined1.stan', line 2, column 12 to column 23:
3+
-------------------------------------------------
4+
1: model {
5+
2: target += foo_lpdf(1);
6+
^
7+
3: }
8+
-------------------------------------------------
9+
10+
A returning function was expected but an undeclared identifier 'foo_lpdf' was supplied.
11+
$ ../../../../../install/default/bin/stanc completely_undefined2.stan
12+
Semantic error in 'completely_undefined2.stan', line 5, column 12 to column 23:
13+
-------------------------------------------------
14+
3: }
15+
4: model {
16+
5: target += foo_lpdf(1);
17+
^
18+
6: }
19+
-------------------------------------------------
20+
21+
Function 'foo_lpdf' is not implemented for distribution 'foo', use 'foo_lpmf' instead.
122
$ ../../../../../install/default/bin/stanc deprecated_suffix.stan
223
Semantic error in 'deprecated_suffix.stan', line 4, column 14 to column 40:
324
-------------------------------------------------

0 commit comments

Comments
 (0)