fix: protocol method calls arity-check (issue 0131)
emitProtocolDispatch now requires the user-arg count to equal the protocol method's parameter list — exact, since protocol signatures have no defaults, packs, or variadics — and emits the same "expects N arguments, but M were given" diagnostic plain calls get. Previously extra args were silently dropped (and missing args left the thunk reading garbage). The dispatch gains the call-site span for the diagnostic. examples/1634 pins the rejection; full sweep confirms no existing code relied on the leniency.
This commit is contained in:
12
examples/1634-protocol-call-arity.sx
Normal file
12
examples/1634-protocol-call-arity.sx
Normal file
@@ -0,0 +1,12 @@
|
||||
// issue 0131 regression: a protocol method call must arity-check like a
|
||||
// plain call. `Allocator.dealloc_bytes` declares (ptr); calling it with
|
||||
// an extra argument used to compile and silently drop the extra.
|
||||
#import "modules/std.sx";
|
||||
|
||||
main :: () -> i32 {
|
||||
gpa := GPA.init();
|
||||
a : Allocator = xx gpa;
|
||||
p := a.alloc_bytes(64);
|
||||
a.dealloc_bytes(p, 12345);
|
||||
return 0;
|
||||
}
|
||||
1
examples/expected/1634-protocol-call-arity.exit
Normal file
1
examples/expected/1634-protocol-call-arity.exit
Normal file
@@ -0,0 +1 @@
|
||||
1
|
||||
5
examples/expected/1634-protocol-call-arity.stderr
Normal file
5
examples/expected/1634-protocol-call-arity.stderr
Normal file
@@ -0,0 +1,5 @@
|
||||
error: 'dealloc_bytes' expects 1 argument, but 2 were given
|
||||
--> examples/1634-protocol-call-arity.sx:10:5
|
||||
|
|
||||
10 | a.dealloc_bytes(p, 12345);
|
||||
| ^^^^^^^^^^^^^^^
|
||||
0
examples/expected/1634-protocol-call-arity.stdout
Normal file
0
examples/expected/1634-protocol-call-arity.stdout
Normal file
Reference in New Issue
Block a user