fix: validate protocol impl method signatures vs the protocol declaration (issue 0178)

The issue-0176 conformance gate was name-only, so an impl P for T with a
mismatched return/param type (or arity) built a wrong-ABI thunk that
silently miscompiled (exit 0, wrong value). firstUnimplementedMethod now
validates arity (after self), each param type, and the return type
against the protocol declaration, substituting protocol Self->concrete
via resolveProtoTypeSubSelf (recurses through pointer/many-pointer/
optional/slice/array so []Self<->[]T match; conservative .unresolved for
Self-in-generic-arg). Comparison is by structural formatTypeName
(alias/module/spelling independent); typesClearlyDiffer skips when either
side has an unresolved leaf at any depth, biasing against false-positives.

Regressions: diagnostics/1201 (negative), protocols/0420 (positive,
[]Self param). Verified by 3+3 adversarial reviews (a mid-fix []Self
false-positive was found and closed); suite 792/0.
This commit is contained in:
agra
2026-06-23 08:48:31 +03:00
parent 8b613af96b
commit c41f51aed3
10 changed files with 293 additions and 2 deletions

View File

@@ -0,0 +1,5 @@
error: 'T' does not implement protocol 'P': method 'val' has a mismatched signature — return type: protocol declares 'i64', impl declares 'bool' (a protocol-method impl must match the protocol's declared types exactly, with `Self` written as `T`)
--> examples/diagnostics/1201-diagnostics-protocol-impl-signature-mismatch.sx:20:3
|
20 | p : P = t; // <- 'T' does not implement 'P' (return type)
| ^^^^^^^^^^