Diagnostic and cause
LinkRedeclaration
- Family
- topaz
- Phase
- check
- Code
TPZ5008
Cause and conditions
A protocol implementation must not define the same method twice. A duplicate method is rejected with TPZ5008 at the later method name.
Related rule: A protocol implementation defines each method onceResponse
Rename or remove the later duplicate. Use a nested scope when a separate local binding is intended.
Source evidence
- compiler/crates/topaz_diag/src/explain.rs at
151141d7bb44· 665-677 - compiler/crates/topaz_product_runtime/src/diagnostic.rs at
151141d7bb44· 69-69 - compiler/crates/topaz_self_frontend/topaz/checker/expression_control.tpz at
151141d7bb44· 646-646 - compiler/crates/topaz_self_frontend/topaz/checker/expression_core.tpz at
151141d7bb44· 1964-1964 - compiler/crates/topaz_self_frontend/topaz/checker/nominals.tpz at
151141d7bb44· 812-812 - compiler/crates/topaz_self_frontend/topaz/checker/patterns.tpz at
151141d7bb44· 789-789 - compiler/crates/topaz_self_frontend/topaz/checker/protocols_methods.tpz at
151141d7bb44· 351-351 - compiler/crates/topaz_self_frontend/topaz/checker/statements.tpz at
151141d7bb44· 273-273 - compiler/crates/topaz_self_frontend/topaz/checker/protocols_methods.tpz at
151141d7bb44· 337-360 - compiler/crates/topaz_self_frontend/topaz/checker/syntax_index.tpz at
151141d7bb44· 485-505
Compiler phase: check/runtime.
Compiler explanation: A scope declares the same value name more than once.
Message templates. The marker ⟨value⟩ stands for text computed for the reported program.
- duplicate concurrent arm
⟨value⟩Source - field
⟨value⟩is given twice in⟨value⟩Source - record field
⟨value⟩is declared twice in⟨value⟩Source - method
⟨value⟩is already declared in protocol⟨value⟩Source ⟨value⟩is a builtin protocol and cannot be redeclared Source- protocol
⟨value⟩is already declared Source - nominal record pattern field
⟨value⟩is specified more than once Source ⟨value⟩is already declared in this scope Source- method
⟨value⟩is implemented twice inimpl ⟨value⟩<⟨value⟩>Source - method
⟨value⟩is already defined for⟨value⟩Source ⟨value⟩is already declared in this scope Source⟨value⟩is already declared in this scope Source
Observed for the candidate in Topaz 5.21.3. Execution
- error[TPZ5008]: method
showis implemented twice inimpl Show<Item>
A protocol implementation must not define the same method twice. A duplicate method is rejected with TPZ5008 at the later method name.
A protocol implementation defines each method once
A protocol implementation must not define the same method twice. A duplicate method is rejected with TPZ5008 at the later method name.
Source evidence
- compiler/crates/topaz_self_frontend/topaz/checker/protocols_methods.tpz at
151141d7bb44· 337-360 - compiler/crates/topaz_self_frontend/topaz/checker/syntax_index.tpz at
151141d7bb44· 485-505
Response
LinkRename or remove the later duplicate. Use a nested scope when a separate local binding is intended.
Reproduction and verification
LinkRejected program
Linkrecord Item { value: int }impl Show<Item> {function show(value: Item) -> string { "first" }function show(value: Item) -> string { "second" }}
No stdout.
Expected result
Source evidence
- compiler/crates/topaz_self_frontend/topaz/checker/protocols_methods.tpz at
151141d7bb44· 337-360 - compiler/crates/topaz_self_frontend/topaz/checker/syntax_index.tpz at
151141d7bb44· 485-505
Repaired program
Linkrecord Item { value: int }impl Show<Item> {function show(value: Item) -> string { "first" }}
Expected result
Expected result
Checking accepts the program. Exit code 0.
Source evidence
- compiler/crates/topaz_self_frontend/topaz/checker/protocols_methods.tpz at
151141d7bb44· 337-360 - compiler/crates/topaz_self_frontend/topaz/checker/syntax_index.tpz at
151141d7bb44· 485-505