Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Schema Magnolia Derivation inlines a null that breaks Scala 3's -Yexplicit-nulls compiler option #3967

Closed
coryfklein opened this issue Aug 5, 2024 · 1 comment · Fixed by #3970 or #3977

Comments

@coryfklein
Copy link
Contributor

Tapir version: 1.10.15

Scala version: 3.4.2

The generated example Tapir project won't compile with Scala 3's -Yexplicit-nulls compiler option due to how SchemaMagnoliaDerivation#derived inlines an unsafe call to java.lang.ThreadLocal#get

What is the problem?

Generate a project with these settings:
image

Then turn on the -Yexplicit-nulls flag.

You can see the issue manifesting in booksListing in my IntelliJ setup like so:

image

Error at the end of line 40

Found:    scala.collection.mutable.Set[String] | Null
Required: scala.collection.mutable.Set[String]

Explanation
===========

Tree:       9|SchemaMagnoliaDerivation_this.
    119|  sttp$tapir$generic$auto$SchemaMagnoliaDerivation$$inline$deriveCache.
    119|  get()
I tried to show that
  scala.collection.mutable.Set[String] | Null
conforms to
  scala.collection.mutable.Set[String]
but none of the attempts shown below succeeded:

  ==> scala.collection.mutable.Set[String] | Null  <:  scala.collection.mutable.Set[String]
    ==> Null  <:  scala.collection.mutable.Set[String]  = false

The tests were made under a constraint with:
 uninstantiated variables: T, A, T, A
 constrained types: [T](value: T): sttp.tapir.generic.Derived[T],
  [A](elems: A*): scala.collection.mutable.Set[A],
  [T]
    (schemaType: sttp.tapir.SchemaType[T],
      name: Option[sttp.tapir.Schema.SName], isOptional: Boolean,
      description: Option[String], default: Option[(T, Option[Any])],
      format: Option[String], encodedExample: Option[Any],
      deprecated: Boolean, hidden: Boolean,
      validator: sttp.tapir.Validator[T], attributes:
      sttp.tapir.AttributeMap): sttp.tapir.Schema[T]
  ,
[A](using x$1: scala.deriving.Mirror.Of[A]): sttp.tapir.Schema[A]
 bounds:
     T
     A
     T
     A
 ordering:
 co-deps:
 contra-deps:
 [30:36]
@adamw
Copy link
Member

adamw commented Aug 6, 2024

Do you think that #3970 will satisfy the compiler? I'm not familiar with explicit-nullss

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants