Open dustincatap opened 1 year ago
I can reproduce with just
class X {
void m({bool b = kIsWeb}) { print(b); }
}
(package:auto_route
uses !kIsWeb
as a default value, but just kIsWeb
is enough).
The thing is kIsWeb
is defined using bool.fromEnvironment
and I guess Analyzer has no chance of knowing what the environment is.
@srawlins Could you please confirm this never worked and this is not a regression?
Corr: it's not just bool.fromEnvironment
but specifically bool.fromEnvironment('dart.library.js_util')
that results in bool (-unknown-)
value.
As a quick fix we could probably detect this and try just referencing the constant instead. Won't work with !kIsWeb
though.
Longer term I had an idea how we could get rid of the need to revive default values:
void m({C x = kC})
, then calls m()
and m(x: kC}
should result in the same invocations, so when we override m
, we have to also reconstruct kC
, which could be a problem, if it involves private things. Or, as we see now, it could also be constant but unknown.void m({C? x = _guardC})
. This will make invocations m()
and m(x: kC)
non equal though, so we would have to check x == _guardC
and do something about it._ProxyX
class alongside with MockX
, but without any overrides, just nSM, we could call it and get the correct default values.That's just a sketch but I think it could be made to work. At the same time it seems a bit too complex.
So probably even a longer term we should do a breaking API change and separate mocks from their configuration objects as Lasse proposed long ago. So config object will be generated but it won't need any default args. And mocks won't have any overrides except for nSM, so they will get the right default values for free.
@dustincatap For you one possible fix will be to wrap RootStackRouter
in a class of your own (making sure you don't have kIsWeb
as an argument default value) and mock that instead. So far I think that's the only option.
We could come up with some quick fix, but I can't promise that. And a longer term solution won't be implemented any time soon.
Hi. I don't know if this issue is valid for this repository.
I am having trouble generating mocks when using
auto_route
.Running
dart run build_runner build --verbose
outputs this error:Here is a sample project