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

Type alias is not passed to freezed #686

Closed
jonasfranz opened this issue Jun 14, 2022 · 2 comments
Closed

Type alias is not passed to freezed #686

jonasfranz opened this issue Jun 14, 2022 · 2 comments
Labels
bug Something isn't working needs triage

Comments

@jonasfranz
Copy link

Describe the bug
If you have two classes with the same name but different packages (e.g. Timer from dart:async and a custom class) freezed will use just one of those classes for both types resulting in a compile time error.

To Reproduce

Create a class that has a conflicting name:

class Timer { }

Create a freezed class that uses both conflicting classes:

import 'dart:async' as async;

import 'package:example/timer.dart';
import 'package:freezed_annotation/freezed_annotation.dart';

part 'timer_state.freezed.dart';

typedef AsyncTimer = async.Timer;

@freezed
class TimerState with _$TimerState {
  const TimerState._();
  const factory TimerState({
    @Default({}) Map<Timer, async.Timer> timerNotifications,
  }) = _TimerState;
}

Run the freezed generator.

Expected behavior

I would expect that the corresponding freezed part class uses the same aliased class name (async.Timer). But it uses the un-aliased class name resulting in a compile time error since the constructor signatures don't match.

Part of the generated code:

/// @nodoc
mixin _$TimerState {
  Map<Timer, Timer> get timerNotifications =>
      throw _privateConstructorUsedError;

  @JsonKey(ignore: true)
  $TimerStateCopyWith<TimerState> get copyWith =>
      throw _privateConstructorUsedError;
}
@jonasfranz jonasfranz added bug Something isn't working needs triage labels Jun 14, 2022
@jonasfranz
Copy link
Author

Might be an duplicate of #628

@rrousselGit
Copy link
Owner

Closing in favor of #628

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working needs triage
Projects
None yet
Development

No branches or pull requests

2 participants