mrousavy / nitro

🔥 Insanely fast native C++, Swift or Kotlin modules with a statically compiled binding layer to JSI
https://nitro.margelo.com
MIT License
642 stars 22 forks source link

fix: Fix "legacy" `enum`s breaking Swift compiler #346

Closed mrousavy closed 3 days ago

mrousavy commented 3 days ago

Previously, we only tested a string enum (discriminating union):

type Powertrain = 'gas' | 'electric'

Now, we also test an "old" enum, aka an enum backed by a number:

enum Powertrain { GAS, ELECTRIC }

This is a slightly different implementation on the native side, since we now use the number as a value of truth.

On iOS, for some reason this breaks when using std::optional<Enum>.

This code breaks:

      self.__implementation.optionalOldEnum = newValue.value

This code works:

      self.__implementation.optionalOldEnum = newValue.has_value() ? newValue.pointee : nil

So this PR fixes this. And adds a test.

vercel[bot] commented 3 days ago

The latest updates on your projects. Learn more about Vercel for Git ↗︎

1 Skipped Deployment | Name | Status | Preview | Comments | Updated (UTC) | | :--- | :----- | :------ | :------- | :------ | | **nitro-docs** | ⬜️ Skipped ([Inspect](https://vercel.com/margelo/nitro-docs/2fyNzBcPgkFVdbnmxsDBLqrh6bMb)) | | | Nov 19, 2024 0:20am |