CompeyDev / CompeyDev/rusty-luau
Issues with Option and Result type self-convertibility
- Dominant language
- Luau
- Stars
- 9
- Forks
- 2
- PR merge metrics
- No merged PRs in 30d
Description
I noticed in my current project that some Option cannot be considered convertible to Option where T == T, based upon the things luau-analyze is telling me under strict mode, causing other parts of my project to have types that are considered dissimilar where, e.g. Dependency == Dependency, because of the use of Option where T is fsx.FileMetadata, containing itself Option for filetypes, ...
I have attempted to fix this in a hodgepodge attempt at making Option actually capable of being self-convertible, I have not changed documentation for this attempted fix, I have tested it against my own project. Here be dragons, use at your own risk, blah blah blah.
I do not know if you can reproduce the actual underlying issue I had, but you should be able to see it with the use of luau-analyze with languageMode: strict.
Zip cannot use :isSome() without unwrap. If you want to use direct reference to its inner, you must use ~= nil. This is because you must remove the potential for T? directly, one way or another. So, you can either use ~= nil in the if for it, or use :unwrap() on the actual option.
For replace, the self reference is equivalent to a pointer; copy the table itself, don't just take the pointer?
After post discoveries: oh no result has the same problem
```
/home/kat/src/glade/src/third-party/rusty-luau/lib/result.luau(111,3): TypeError: Cannot cast '{| _error: E, _value: T, typeId: string |}' in
to 'Result & { _error: E, _value: T, typeId: "Result" }' because the types are unrelated
/home/kat/src/glade/src/third-party/rusty-luau/lib/result.luau(140,20): TypeError: Type 'T | never' could not be converted into 't1 where t1
= {- ['a]: t1 -}'
caused by:
Not all union options are compatible.
Type 'T' could not be converted into 't1 where t1 = {- ['a]: t1 -}'
/home/kat/src/glade/src/third-party/rusty-luau/lib/result.luau(140,33): TypeError: Type 'T | never' could not be converted into 't1 where t1
= {- ['a]: t1 -}'
caused by:
Not all union options are compatible.
Type 'T' could not be converted into 't1 where t1 = {- ['a]: t1 -}'
```
In fixing result, tableEq should probably take either or . I was unsure of which actually made sense for it.
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.