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

Import alias v2 #628

Open
rrousselGit opened this issue Apr 2, 2022 · 11 comments
Open

Import alias v2 #628

rrousselGit opened this issue Apr 2, 2022 · 11 comments
Assignees
Labels
bug Something isn't working wontfix This will not be worked on

Comments

@rrousselGit
Copy link
Owner

This bug is marked as closed, but as of 18th Sep. 2021 and version 0.14.5 - it is not (fully fixed). Example:

/// importing library from another package with prefix
import 'package:some_package/core.dart' as core;

@freezed
class ProfileEvent with _$ProfileEvent {
  /// note that core.Profile is _also_ a freezed class
  const factory ProfileEvent.changeTo({required core.Profile profile}) =
      _ChangeTo;
}

Now, this will generate the following syntax errors in .freezed file:

abstract class _$ChangeToCopyWith<$Res> {
  factory _$ChangeToCopyWith(_ChangeTo value, $Res Function(_ChangeTo) then) =
      __$ChangeToCopyWithImpl<$Res>;
  $Res call({core.Profile profile}); // note: generator adds prefix correctly here

  $ProfileCopyWith<$Res> get profile; // syntax error: Undefined class '$ProfileCopyWith'.
}
class __$ChangeToCopyWithImpl<$Res> extends _$ProfileEventCopyWithImpl<$Res>
    implements _$ChangeToCopyWith<$Res> {
/// [ .. lines removed .. ]
  @override
  $ProfileCopyWith<$Res> get profile { // Syntax error: Undefined class '$ProfileCopyWith'.
    return $ProfileCopyWith<$Res>(_value.profile, (value) { // same syntax error as above
      return _then(_value.copyWith(profile: value));
    });
  }

Currently, my workaround is to edit the .freezed files manually adding the prefix everywhere where there are syntax errors:

core.$ProfileCopyWith<$Res>

@rrousselGit : Please advise if I should open a new bug for this, alternatively, this bug probably should be repoened.

Originally posted by @matekdk in #70 (comment)

@rrousselGit rrousselGit added the bug Something isn't working label Apr 2, 2022
@Haidar0096
Copy link

Haidar0096 commented Jun 6, 2022

@rrousselGit any workaround other than manually editing the generated file everytime? I depend heavily on freezed in my app and this is causing alot of problems since I have many conflicting imports in my freezed classes??

I am also running the generator in "watch" mode so every code change triggers rebuild of the freezed files as well.

@jibbers42
Copy link

I'm seeing this with code that looks basically like:

@freezed
class MyType with _$MyType {
  const factory MyType({
    required myalias.OtherType ot1,
    required List<myalias.OtherType> ot2,
  }) = _MyType;
}

The alias for ot1 is kept, but the alias for ot2, used a type parameter, is lost.

mixin _$MyType {
  n1.OtherType get ot1 => throw _privateConstructorUsedError;
  List<OtherType> get ot2 => throw _privateConstructorUsedError; // this line errors

@LaysDragon
Copy link

yes,I bump into this bug too.Import a freezed class with alias will lost the alias on its CopyWith method in generated file.Its seems like the #519

@elango10
Copy link

elango10 commented May 3, 2023

I can imagine the magnitude of addressing this bug, but this issue is only going to get worse as more and more flutter packages are developed. We have classes with names such as User and Message that produce conflicts, and another situation where two external packages also produce a conflict.

At the moment, we have to wrap our conflicts with another freezed shell model which works, but it is not a pretty or sustainable solution for freezed future use.

@rrousselGit
Copy link
Owner Author

I won't work on this until we have metaprogramming.

Metaprogramming involves a complete rewrite of Freezed, and comes natively with a solution to this problem. I don't want to put a lot of effort into this when it's naturally going to disappear.

@rrousselGit rrousselGit added the wontfix This will not be worked on label May 3, 2023
@rrousselGit rrousselGit self-assigned this May 10, 2023
@hiroshihorie
Copy link

So unfortunate this bug still exists...

@LaysDragon
Copy link

So unfortunate this bug still exists...

all we can do now is waiting the Metaprogramming

@ycherniavskyi
Copy link

ycherniavskyi commented Sep 16, 2023

Encountered this issue with Set<data.Company> today 😟.
Does anyone have information on the roadmap for Dart Metaprogramming?

@LaysDragon
Copy link

They are discussing here,it seems like it's not going to completed right away.
dart-lang/language#1482
https://github.com/dart-lang/language/blob/main/working/macros/feature-specification.md

@Caeruleo
Copy link

Hey i'm also facing this issue.

First of all thanks for this awesome package <3.

I now it's not being fixed until metaprograming is released, but maybe it could be a warning of this issue as a current "limitation" of the package at the doc.

@myConsciousness
Copy link

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working wontfix This will not be worked on
Projects
None yet
Development

No branches or pull requests

9 participants