jamescourtney / FlatSharp

Fast, idiomatic C# implementation of Flatbuffers
Apache License 2.0
510 stars 51 forks source link

FlatSharp output seemingly incompatible with Unity 2019 #243

Closed yewnyx closed 3 years ago

yewnyx commented 3 years ago

#nullable disable and #nullable enable annotations produce compilation errors, as do the ! and ? sprinkled throughout.

This was tested with both dotnet path\to\FlatSharp.Compiler.dll -i path\to\MySchema.fbs -o path\to\output --nullable-warnings=true and dotnet path\to\FlatSharp.Compiler.dll -i path\to\MySchema.fbs -o path\to\output --nullable-warnings=false (or with the option omitted altogether), and produce output that can't be compiled in Unity 2019.4, whose language support is C# 7.3.

jamescourtney commented 3 years ago

FlatSharp targets C# 8.0, which looks like you need Unity version 2020.2 or greater.

yewnyx commented 3 years ago

Gotcha. A little disappointing that I'll have to wait to use it, but understandable.

For some clarity, Unity comes out with a new version every year, and it typically starts stabilizing towards the end of the year before becoming LTS. Devs will often track the LTS -1 and update to the next LTS after it's baked for a little bit, so 2019 and 2020 will be the best targets for 2021, and 2020 and 2021 the best targets for 2022, and so on.

jamescourtney commented 3 years ago

Thanks for that context. I don't have too much experience with Unity, unfortunately.

If you're wiling to use an older version of FlatSharp, I think 4.X uses C# 7.3 or less. It doesn't contain many of the newer features, but still has the compiler and most things you'd expect.

yewnyx commented 3 years ago

Appreciate the tip, I'll try that out!

yewnyx commented 3 years ago

reporting back - 4.2.2 generated code with calls to functions that didn't exist (different number of parameters), i.e. ParseItem, WriteUOffset, GetAbsoluteTableFieldLocation, etc.

jamescourtney commented 3 years ago

Did you also downgrade FlatSharp.Runtime to 4.2.2? Versions are tied together.

yewnyx commented 3 years ago

D'oh! I did indeed forget that. Once I fixed expressions such as index3Value is not null to index3Value != null, it compiled. Thanks!

jamescourtney commented 3 years ago

Glad it worked. If you're willing to fiddle with the code, then removing the extra ?'s and !'s shouldn't be too bad if you want to use the new version. There might be a few 8.0-only things, but probably not more than a handful.

Those are related to nullable reference types, if you aren't familiar. The reason I include them is that the annotations are very helpful, and I compile my unit tests with warnings-as-errors so I get hard breaks if I forgot to check for null.