-
Notifications
You must be signed in to change notification settings - Fork 107
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add Reviver #679
Open
Nexushunter
wants to merge
4
commits into
dart-lang:master
Choose a base branch
from
Nexushunter:reviver
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Add Reviver #679
Conversation
This file contains 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
Nexushunter
commented
Sep 24, 2023
Comment on lines
+174
to
+188
List<T>? toTypedList<T>(T t) => reader.listValue | ||
.map((e) => Reviver.fromDartObject(e).toInstance() as T) | ||
.toList() as List<T>?; | ||
|
||
Map<KT, VT>? toTypedMap<KT, VT>(KT kt, VT vt) => reader.mapValue.map( | ||
(key, value) => MapEntry( | ||
Reviver.fromDartObject(key).toInstance() as KT, | ||
Reviver.fromDartObject(value).toInstance() as VT, | ||
), | ||
) as Map<KT, VT>?; | ||
|
||
Set<T>? toTypedSet<T>(T t) => reader.setValue | ||
.map((e) => Reviver.fromDartObject(e).toInstance() as T) | ||
.toSet() as Set<T>?; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Trying to leverage these results in the following stack trace:
dart:collection MapBase.map
package:source_gen/src/constants/reviver.dart 178:68 Reviver.toTypedMap
package:source_gen/src/constants/reviver.dart 93:16 Reviver.toInstance
package:source_gen/src/constants/reviver.dart 142:51 Reviver.namedValues.<fn>
dart:collection MapBase.map
package:source_gen/src/constants/reviver.dart 139:74 Reviver.namedValues
package:source_gen/src/constants/reviver.dart 109:18 Reviver.toInstance
package:source_gen/src/constants/reviver.dart 135:50 Reviver.positionalValues.<fn>
dart:_internal ListIterable.toList
package:source_gen/src/constants/reviver.dart 137:8 Reviver.positionalValues
package:source_gen/src/constants/reviver.dart 108:18 Reviver.toInstance
test/constants/reviver_test.dart 56:38 main.<fn>.<fn>.<fn>.<fn>
This feels wrong. The reason I'm doing this is because there is a limitation of not being able to do:
final t = Reviver.fromDartObject(reader.listValue.first)
.toInstance()
.runtimeType;
return reder.listValue.map((e) => Reviver.fromDartObject(e).toInstance() as t).toList();
Opening this early to get some feedback and thoughts. |
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.
Motive
I work on a project to provide a dart annotation that allows us to run the OpenAPI generator from a Dart defined config.
I was looking to provide a clean way to test our annotation and ensure that consumer could use a custom header delegate. In this case I wanted an easy way to be able to generically restore a header delegate that a user may provide but would like to have been able to avoid needing to know about their implementation details. ie User creates a subclass, they use the builder we provide and our builder needs to know nothing of their implementation details.
To help facilitate this it would be nice if the source_gen library had a way to revive the object in memory allowing for us to clean separate ownership (external library function vs internal library function).
While I know that the
dart:mirrors
library is classified as unstable it would be very beneficial to be able to have a solution provided to the community. This would also help with not having the need (though they could still be used) for packages like generic_reader.Changes
Reviver
class that usesdart:mirrors
to reflect aConstantReader
/DartObject?
into an in memory representation.Contribution guidelines:
dart format
.Note that many Dart repos have a weekly cadence for reviewing PRs - please allow for some latency before initial review feedback.