E0077: native_primitive_shadowed
E0077 native_primitive_shadowed — a handler named like a native primitive.
A compile-time error of soma check, the checker of the Soma programming language (soma explain E0077).
The rule
Inside a [native] handler, a call to a native-only primitive (such as hm_inc, buffer or sb_push) reaches the primitive even when the program defines a handler with the same name, while the same call in an interpreted handler reaches the handler. Check refuses the program so that one name does not mean two things. Rename your handler (here bump_bin).
A program that triggers it
wrong.cell
cell Histogram {
on hm_inc(bins: Map<String, Int>, key: String) {
bins[key] = (bins[key] ?? 0) + 1
return bins
}
on count_mod(n: Int, m: Int) [native] {
let h = hashmap()
for i in range(0, n) {
hm_inc(h, i % m)
}
return hm_len(h)
}
}What soma check prints:
$ soma check wrong.cell
error: `hm_inc(…)` in the [native] handler `count_mod` is the primitive, not the handler `hm_inc` this program defines — the same call in an interpreted handler goes to the handler, so one name means two things. Rename the handler (`on hm_inc_of(…)`)
--> wrong.cell:9:13
|
9 | hm_inc(h, i % m)
| ^
= code: E0077
✗ 1 error(s), 0 warning(s).The fix field of soma check --json: the same call in an interpreted handler goes to the handler, so one name means two things. Rename the handler (`on hm_inc_of(…)`)
The fix
On line 2, on hm_inc(bins: Map<String, Int>, key: String) { becomes on bump_bin(bins: Map<String, Int>, key: String) {.
wrong.cell → right.cell
--- wrong.cell
+++ right.cell
@@ -1,4 +1,4 @@
cell Histogram {
- on hm_inc(bins: Map<String, Int>, key: String) {
+ on bump_bin(bins: Map<String, Int>, key: String) {
bins[key] = (bins[key] ?? 0) + 1
return binsWith the fix, soma check accepts the program:
$ soma check right.cell
✓ All checks passed.