mobxjs / mobx.dart

MobX for the Dart language. Hassle-free, reactive state-management for your Dart and Flutter apps.
https://mobx.netlify.app
MIT License
2.39k stars 310 forks source link

Can't use nullable type alias in computed; `null check operator used on null value` #968

Closed clangenb closed 8 months ago

clangenb commented 9 months ago

I have a @computed defined like this:

typedef BlockHash = Uint8List;

@computed
BlockHash? get latestHash {
  // Workaround for https://dart.dev/tools/non-promotion-reasons#property.
  final hash = latestHashHex;
  if (hash != null) {
    // return null;
    return BlockHash.fromList(hex.decode(hash.replaceFirst('0x', '')));
  } else {
    return null;
  }
} 

When I ran the build runner, it gave me a null check operator used on null value error. However, when I fill in the original type Uint8List it works.

Even more interestingly, if I replace the Uint8List with the BlockHash after a successful build, it works, but it keeps the Uint8List in the generated file.

amondnet commented 8 months ago

@clangenb The code is generated without any issues. Could you please provide a reproducible code?

clangenb commented 8 months ago

Ok, I see. Interesting. I have assumed that my code is minimal enough to rule out that this error is from something else. I will revisit this soon, but close this issue now under the assumption that the error is due to my code.