You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm currently developing Kotlin language support in order to bring Kaitai Struct to the Kotlin Multiplatform world. For now I've implemented most of the things and the implementation is able to pass 231 out of 233 tests on JVM and MacOS ARM64 targets.
But there's an issue with 7 of them related to kotlin's Null Safety concept.
There are at least two main operators in Kotlin exist to provide null-safety support - Non-null Assertion Operator (!!) and Safe Calls Operator (?.). The main issue is with the safe call operator - in order to use it and in order to be able to perform safe call chaining, both compiler and translator should be aware of nullability of each type.
I've came up with two approaches which could help resolve this issue. Let's pick NavParentRecursive and it's test as an example.
The most interesting part of the test looks like this:
Using this approach we can simply make every attributeReader return non-nullable type by requiring attribute being not null explicitly. Nullability in instances can be handled in the same way.
More on this
Pros:
easy to implement
already works
Cons:
on the call site it is unclear will reading fail or not
nullability is basically unmanageable
need to adjust tests by replacing assertNull with assertFails
In order to do so we need to be able to know if the lvalue nullable or not and propagate nullability to the right side. Moreover there's one more caveat: if expression is used as parameter, we need to now if target function accepts nullable parameters and perform non-null assertion in some cases.
As the bottom line, I believe it would be much better to extend nullability support, at least for the Kotlin implementation.
I'm not sure that approach with adjusting the whole DataType system with, for example isNullable flag is the proper way to implement null safety support. Therefore I'm looking for some help with this using that or alternative approach.
In short, there are very few things needs to be done:
a way to resolve nullability of expression
a way to resolve nullability of a combined type
a way to provide nullability with the DataType itself
ability to translate expressions depending on operand's type nullability
The text was updated successfully, but these errors were encountered:
Hello!
I'm currently developing Kotlin language support in order to bring Kaitai Struct to the Kotlin Multiplatform world. For now I've implemented most of the things and the implementation is able to pass 231 out of 233 tests on JVM and MacOS ARM64 targets.
But there's an issue with 7 of them related to kotlin's
Null Safety
concept.There are at least two main operators in Kotlin exist to provide null-safety support -
Non-null Assertion Operator (!!)
andSafe Calls Operator (?.)
. The main issue is with the safe call operator - in order to use it and in order to be able to performsafe call chaining
, both compiler and translator should be aware of nullability of each type.I've came up with two approaches which could help resolve this issue. Let's pick
NavParentRecursive
and it's test as an example.The most interesting part of the test looks like this:
We don't care about null
Using this approach we can simply make every
attributeReader
return non-nullable type by requiring attribute being not null explicitly. Nullability in instances can be handled in the same way.More on this
Pros:
Cons:
assertNull
withassertFails
Giving that adjusting test as follows:
Nullable types should be supported at
DataType
levelUsing this approach wi need to be able to propagate nullability to the resulting type of every expression.
More on this
Pros:
Cons:
DataType
layerDataType? %op% DataType
in order to resolve resulting nullabilityGiving that if we declare attribute reader's type nullable like this:
compiler should be able to generate something like this:
In order to do so we need to be able to know if the
lvalue
nullable or not and propagate nullability to the right side. Moreover there's one more caveat: if expression is used as parameter, we need to now if target function accepts nullable parameters and perform non-null assertion in some cases.As the bottom line, I believe it would be much better to extend nullability support, at least for the Kotlin implementation.
I'm not sure that approach with adjusting the whole
DataType
system with, for exampleisNullable
flag is the proper way to implement null safety support. Therefore I'm looking for some help with this using that or alternative approach.In short, there are very few things needs to be done:
DataType
itselfThe text was updated successfully, but these errors were encountered: