E02050: same trait referenced multiple times
What went wrong
The same trait is listed multiple times in a 'with trait of' clause. Each trait should only appear once in the declaration. Every trait listed more than once is named in the one error ('T1', 'T2').
Worked examples
Compilable examples demonstrating this error and the correct fix:
- ek9 -q 740 (How does EK9 detect duplicate trait references and servic...)
How to fix it
- Remove the duplicate trait from the list
- Check for same trait via different paths (module::T1 vs T1)
Common causes
- Copy-paste error in trait list
- Same trait referenced with and without module qualifier
Note
The same trait CAN be reached more than once through the INHERITANCE hierarchy (two different listed traits that share it - a diamond). This error is specifically about direct duplicate listing in a single 'with trait of' clause; listing a trait that another listed trait, or the super class, already has is E02090.
See also
Examples
Every example is compiled by the EK9 compiler: the first fails exactly as captioned, the others fix it.
Fails with E02050: same trait referenced multiple times
#!ek9 defines module error.e02050.bad defines trait T1 method1() <- rtn <- true T2 method2() <- rtn <- true DuplicatedReferences1 with trait of T1, T2, T1 method3() <- rtn <- true DuplicatedReferences2 with trait of error.e02050.bad::T1, T2, error.e02050.bad::T1 method3() <- rtn <- true DuplicatedReferences3 with trait of error.e02050.bad::T1, T2, T1 method3() <- rtn <- true DuplicatedReferences4 with trait of T1, T2, T1, T2, T1 method3() <- rtn <- true
Fixed: Name each trait once in the 'with trait of' list
#!ek9 defines module error.e02050.good defines trait T1 method1() <- rtn <- true T2 method2() <- rtn <- true BothTraits with trait of T1, T2 method3() <- rtn <- true
Questions and answers
These Q&A entries show E02050 and its fix: