E06190: EK9 Result must be used with two different types

Category: E06xxx Type hierarchy checks · Reported in phase: EXPLICIT_TYPE_SYMBOL_DEFINITION · Classification: RESULT_MUST_HAVE_DIFFERENT_TYPES · All error codes

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

  1. Change one type parameter to a different type
  2. Create wrapper record/class if both must contain similar data
  3. 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

  • E06190: Result same types for success/error (this error)
  • E06330: incompatible type arguments in generic

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: