Skip to content
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

fix: type safety in Matrix Dart SDK database #1679

Conversation

TheOneWithTheBraid
Copy link
Contributor

  • removes unsafe casts
  • builds list using List.from constructor
  • removes unwanted late statement

Got the following premium bug report sent via matrix :

bug-report

- removes unsafe casts
- builds list using List<T>.from constructor
- removes unwanted late statement

Signed-off-by: The one with the braid <[email protected]>
@TheOneWithTheBraid
Copy link
Contributor Author

Fixes: krille-chan/fluffychat#794

@@ -433,7 +434,7 @@ class MatrixSdkDatabase extends DatabaseApi {
? timelineEventIds.getRange(start, end).toList()
: []);

return await _getEventsByIds(eventIds.cast<String>(), room);
return await _getEventsByIds(eventIds, room);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This has already been fixed here: 2afd704

List<Map<String, dynamic>>.from(
childEntries.whereType<Map<String, dynamic>>()),
List<Map<String, dynamic>>.from(
crossSigningEntries.whereType<Map<String, dynamic>>()),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

List<T>.from() is not better than list.cast<T>() as it crashes in the same way when there is an entry which is not T. The difference is that List<T>.from() create a non-deep copy. Do we need this here? Also this is unrelated to the bug described in the commit message

@@ -1489,7 +1486,7 @@ class MatrixSdkDatabase extends DatabaseApi {
try {
await clear();
await open();
final json = Map.from(jsonDecode(export)).cast<String, Map>();
final json = Map<String, Map>.from(jsonDecode(export));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here. This does not prevent type errors or makes anything more type safe. It just creates a non-deep copy

@krille-chan
Copy link
Contributor

Seems to be outdated now. Please ping me if I see this wrong

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants