E06190: EK9 Result must be used with two different types
What went wrong
Result<T, E> requires TWO DIFFERENT types - one for success (T) and one for error (E). Using the same type makes it impossible to distinguish success from error at runtime.
Worked examples
Compilable examples demonstrating this error and the correct fix:
- ek9 -q 652 (Why must Result be used with two different types?)
- ek9 -q 48 (How does the Result type work in EK9?)
- ek9 -q 87 (What operations and callbacks does Result support?)
How to fix it
- Change one type parameter to a different type
- Create wrapper record/class if both must contain similar data
- Consider if Result is needed (maybe Optional suffices)
Common causes
- Result of (String, String) - can't tell success from error string
- Accidentally using same type for both parameters
- Not considering runtime distinguishability
See also
Examples
Every example is compiled by the EK9 compiler: the first fails exactly as captioned, the others fix it.
Fails with E06190: EK9 Result must be used with two different types
#!ek9 defines module error.e06190.bad defines function notAllowedWithSameType() as abstract <- rtn as Result of (String, String)?
Fixed: Give Result two different types: the success type and the error type
#!ek9 defines module error.e06190.good defines record Failure reason as String: String() default operator ? defines function parsed() as abstract <- rtn as Result of (String, Failure)?
Questions and answers
These Q&A entries show E06190 and its fix: