Scala 3 Matchable trait and oneOfVariantValueMatcher


I have a scala 3 application with tapir and I’m unsuccessfully trying to use oneOfVariantValueMatcher to define a variant.

My error ADTs:

enum ApplicationError:
  case NotFound

enum EndpointError:
  case Authentication
  case Authorization
  case Application(error: ApplicationError)

I have this code:

oneOfVariantValueMatcher[EndpointError](StatusCode.NotFound, emptyOutputAs(EndpointError.Application(ApplicationError.NotFound))) {
  case EndpointError.Application(ApplicationError.NotFound) => true

The compilation error I get:

pattern selector should be an instance of Matchable, but it has unmatchable type Any instead

In the documentation for Matchable Trait, there is the following statement:

Type Any: if pattern matching is required one should use Matchable instead.

Am I missing something or should the matcher type be PartialFunction[Matchable, Boolean] in scala 3?

Thank you for your help.

1 Like

It’s possible that the macro generates Scala2-like code, however I can’t reproduce the problem. Do you have any compiler flags set maybe, which would enable future options?

1 Like

Indeed I had the flag -source:future enabled. I disabled it and the error is gone.

Thank you for your help, you just saved me a lot of time :slight_smile: