Explain why a value cannot be revived - #820
Open
Yusufihsangorgel wants to merge 4 commits into
Open
Conversation
`reviveInstance` ends with `allResults.first`. When it finds no candidate, the list is empty and the failure surfaces as `Bad state: No element`, with nothing in it to act on. `ConstantReader.revive()` always calls it without an `origin`, so the scan runs over the library of the value's own type. That library is `dart:core` for a literal or a type, never the one the annotation was written in. Throw an `UnsupportedError` naming the value, where it looked, and the readers that do handle it. `ConstantReader.revive()` already throws `UnsupportedError` for a null constant, so the two now agree. Whether the method should return null instead is a separate, breaking question and is left alone.
|
I think that would close the issue While returning null as intended would have been preferred, that ship has mostly sailed after the non-null-by-default update seemingly completely missed this one for over 7 years. So long as the dartdoc mentions the UnsupportedError ahead of time, I think that's all we really need. |
The dartdoc landed on `reviveInstance`, which `source_gen.dart` does not export, so it never renders on pub.dev. Callers reach this through `ConstantReader.revive()`, and that one said nothing about the error.
`_NullConstant.revive()` throws the same error for a null constant, and the first version only documented the missing-reference case.
`revive.dart` says the search for a reference came up empty; the class doc said the value has no reference to recreate, which reads wider than what the code checks.
Author
|
Yeah, it has to be visible before the call. It was only on |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #411
reviveInstanceends withallResults.first, and that list is empty whenever it finds no candidate:revive()never passes anorigin, so the scan runs over the library of the value's own type. That library isdart:corefor a literal or a type, never the one the annotation was written in.UnsupportedErroris what @TekExplorer suggested, and whatrevive()already throws for a null constant. The dartdoc promisednullhere, which the non-nullable return never allowed; it now says what happens.I looked for callers that catch the
StateError.analyzer_buffer, the one #411 points to, catches everything with a barecatch, so only the text it wraps changes.mockitoresolves this version but callsrevive()after ruling out null, literals, and types (_addTypesFromConstantinbuilder.dart).sql_serializablebranches on the error type (config.dart:136) but pinssource_gen: ^1.2.6.Version goes to
4.2.5-wip.