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

Resolve for typedefs/aliases and records in typeArguments & resolve duplicate typedefs #776

Merged
merged 6 commits into from
Dec 4, 2024

Conversation

dickermoshe
Copy link
Contributor

@dickermoshe dickermoshe commented Oct 29, 2024

Closes: #775
Closes: #777
Closes: #778

The fix for these issues is closely related so I've done both of them in a single PR.

  • Mockito wasn't checking for typedefs/aliases in typeArguments
  • it also wasn't looking into records on type args.
  • Typedefs which had the same underlying type were ignored even if the typedef had a different name

These issues cause the dreaded is missing from the asset URI mapping error.

See the related issue for a repro of each of these. I've also added regression tests for all of these.

Looking forward to a swift review!


  • I’ve reviewed the contributor guide and applied the relevant portions to this PR.
Contribution guidelines:

Note that many Dart repos have a weekly cadence for reviewing PRs - please allow for some latency before initial review feedback.

@srawlins
Copy link
Member

CC @mosuem

@dickermoshe dickermoshe changed the title Resolve for typedefs/aliases in typeArguments Resolve for typedefs/aliases and records in typeArguments Oct 29, 2024
@dickermoshe
Copy link
Contributor Author

It seems that the bulk of this code is rely on InterfaceType as the only interface object, while records are interfaces themselves.
It seems that the addTypesFrom function, which until now only took a InterfaceType will now have to take records too.

@dickermoshe dickermoshe marked this pull request as draft October 29, 2024 15:03
@dickermoshe dickermoshe marked this pull request as ready for review October 29, 2024 15:32
@dickermoshe
Copy link
Contributor Author

Could this be cherrypicked into a 5.4.5 release?

@dickermoshe
Copy link
Contributor Author

CI is broken on the entire repo as dart stable does not support analyzer 6.9. Tests pass locally on my machine.

@dickermoshe dickermoshe marked this pull request as draft October 29, 2024 17:04
@dickermoshe dickermoshe marked this pull request as ready for review October 29, 2024 17:05
@dickermoshe dickermoshe changed the title Resolve for typedefs/aliases and records in typeArguments Resolve for typedefs/aliases and records in typeArguments & allow resolve typedefs Oct 29, 2024
@dickermoshe dickermoshe changed the title Resolve for typedefs/aliases and records in typeArguments & allow resolve typedefs Resolve for typedefs/aliases and records in typeArguments & resolve duplicate typedefs Oct 29, 2024
@dickermoshe
Copy link
Contributor Author

@mosuem
I know people hate they get this, but.... Ping

@mosuem
Copy link
Member

mosuem commented Nov 6, 2024

I don't mind at all, but I am also not a maintainer of this repo and maybe not the right person to ping ;) I just stumbled across the same CI error in dart-lang/test#2293

@mosuem
Copy link
Member

mosuem commented Nov 6, 2024

Maybe @srawlins wants to take a look (I hope he you don't mind the ping). I am fine refiling the PR to move to dart-lang/test and merging this first.

Copy link
Member

@srawlins srawlins left a comment

Choose a reason for hiding this comment

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

Thanks so much! I left a few notes but generally the fix is gold 😁

test/builder/auto_mocks_test.dart Outdated Show resolved Hide resolved
test/builder/auto_mocks_test.dart Outdated Show resolved Hide resolved
test/builder/auto_mocks_test.dart Outdated Show resolved Hide resolved
@@ -3553,6 +3553,64 @@ void main() {
expect(mocksContent, contains('class MockBaz extends _i1.Mock'));
expect(mocksContent, contains('implements _i2.Baz'));
});

test('when its a type parameter of function which returns another type',
Copy link
Member

Choose a reason for hiding this comment

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

I'm not sure what you mean here by "a type parameter of function which returns another type." In this test case, the typedef appears to only be used as a type argument in a class definition class Foo extends BaseFoo<CreateBar>.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

How about?
typedef mocks are generated properly when it\'s a function which returns any type

In this instance, Bar was being ignored becuase the return type of CreateBar want being resolved

Copy link
Member

Choose a reason for hiding this comment

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

That SG, thanks!

test/builder/auto_mocks_test.dart Outdated Show resolved Hide resolved
test/builder/auto_mocks_test.dart Show resolved Hide resolved
test/builder/auto_mocks_test.dart Outdated Show resolved Hide resolved
lib/src/builder.dart Outdated Show resolved Hide resolved
CHANGELOG.md Outdated Show resolved Hide resolved
@srawlins
Copy link
Member

srawlins commented Nov 6, 2024

@mosuem I love a friendly ping 😁 I am fine doing whatever procedure works best for you, migrating to dart-lang/test. I think a git commit can be wired up that attributes the fix to @dickermoshe still...

For external PRs like this, I think I've been able to just hand-copy the PR, once landed, into google3, and then re-export. But there might be a good copybara mechanism for that, at this point...

@mosuem
Copy link
Member

mosuem commented Nov 6, 2024

I'll have to check the copybara settings, but normally even g3 SoT repos should be able to accept Github PRs. We can probably copy the config from package:intl, then it should just work.

@mosuem
Copy link
Member

mosuem commented Nov 6, 2024

But please go ahead with merging this, any infra work can wait, features are much nicer ;)

@dickermoshe
Copy link
Contributor Author

Thanks for the timely response. This is the coolest library ever, thank so much!
Fixed all the nits, lmk if there is anything else

@srawlins
Copy link
Member

srawlins commented Dec 3, 2024

Sorry for the delay, we're shipping a big change to the analyzer element model, and analyzer 7.0.0 just dropped. I think we have to do some cleanup on our side before landing this. Hopefully this week. 🤞 I'll stay in touch.

@srawlins
Copy link
Member

srawlins commented Dec 4, 2024

OK we should be good to go. Ship it!

@srawlins srawlins enabled auto-merge (rebase) December 4, 2024 00:28
@srawlins srawlins merged commit dbc9302 into dart-lang:master Dec 4, 2024
5 checks passed
copybara-service bot pushed a commit that referenced this pull request Dec 4, 2024
…uplicate typedefs

#776

Closes: #775
Closes: #777
Closes: #778

The fix for these issues is closely related so I've done both of them in a single PR.

- Mockito wasn't checking for typedefs/aliases in `typeArguments`
- it also wasn't looking into records on type args.
- Typedefs which had the same underlying type were ignored even if the typedef had a different name

These issues cause the dreaded `is missing from the asset URI mapping` error.

See the related issue for a repro of each of these.

I've also added regression tests for all of these.

PiperOrigin-RevId: 702712435
mosuem pushed a commit to dart-lang/test that referenced this pull request Dec 12, 2024
…uplicate typedefs

dart-lang/mockito#776

Closes: dart-lang/mockito#775
Closes: dart-lang/mockito#777
Closes: dart-lang/mockito#778

The fix for these issues is closely related so I've done both of them in a single PR.

- Mockito wasn't checking for typedefs/aliases in `typeArguments`
- it also wasn't looking into records on type args.
- Typedefs which had the same underlying type were ignored even if the typedef had a different name

These issues cause the dreaded `is missing from the asset URI mapping` error.

See the related issue for a repro of each of these.

I've also added regression tests for all of these.

PiperOrigin-RevId: 702712435
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants