lang 2.4: enforce interface-only access on pack elements
A protocol-constrained pack element exposes only the constraint protocol's interface (the locked decision): `xs[i].<member>` is rejected unless `<member>` is one of the protocol's methods. `xs[i].v` (a concrete field of IntCell, not declared on Box) now errors, like a constrained generic — even though the substituted element is concretely an IntCell. monomorphizePackFn records the pack param's constraint protocol in a new `pack_constraint` map (pack-name → protocol); lowerFieldAccess checks it on an `xs[i]` (index_expr) base BEFORE substitution erases the "constrained to P" context. Protocol method calls (`xs[i].get()`) pass — the name is in the protocol. Regression: examples/195-pack-interface-only.sx.
This commit is contained in:
1
tests/expected/195-pack-interface-only.exit
Normal file
1
tests/expected/195-pack-interface-only.exit
Normal file
@@ -0,0 +1 @@
|
||||
1
|
||||
5
tests/expected/195-pack-interface-only.txt
Normal file
5
tests/expected/195-pack-interface-only.txt
Normal file
@@ -0,0 +1,5 @@
|
||||
error: 'v' is not part of protocol 'Box' — a pack element exposes only the protocol's interface
|
||||
--> /Users/agra/projects/sx/examples/195-pack-interface-only.sx:16:12
|
||||
|
|
||||
16 | return xs[0].v; // `v` is not part of Box — error
|
||||
| ^^^^^^^
|
||||
Reference in New Issue
Block a user