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

Functional types are not supported as field types #3

Closed
easazade opened this issue Aug 6, 2021 · 3 comments
Closed

Functional types are not supported as field types #3

easazade opened this issue Aug 6, 2021 · 3 comments
Assignees
Labels
bug Something isn't working good first issue Good for newcomers

Comments

@easazade
Copy link
Contributor

easazade commented Aug 6, 2021

here is the code for the sealed class

import 'package:flutter/material.dart';
import 'package:rekab_delivery/src/util/consumable.dart';
import 'package:rekab_delivery/src/util/typedefs.dart';
import 'package:rekab_delivery/src/widget/src/utils/message.dart';
import 'package:sealed_annotations/sealed_annotations.dart';

part 'login_state.sealed.dart';

@Sealed()
abstract class _LoginState {
  void initial();
  void loading();
  void success(List<String> countries);
  void error(Message msg);
  void invalidNumber();
  void retry(VoidCallback callback);
}

and here is the error i get when running build_runner

[INFO] Generating build script...
[INFO] Generating build script completed, took 675ms

[INFO] Initializing inputs
[INFO] Reading cached asset graph...
[INFO] Reading cached asset graph completed, took 112ms

[INFO] Checking for updates since last build...
[INFO] Checking for updates since last build completed, took 670ms

[INFO] Running build...
[INFO] 1.2s elapsed, 1/3 actions completed.
[INFO] 2.2s elapsed, 1/3 actions completed.
[INFO] 3.3s elapsed, 1/3 actions completed.
[INFO] 10.7s elapsed, 1/3 actions completed.
[INFO] 13.3s elapsed, 2/3 actions completed.
[INFO] 14.5s elapsed, 8/9 actions completed.
[SEVERE] sealed_generators:sealed_generators on lib/src/cubits/login/request/code/login_state.dart:

"SealedError{message={internal error},cause={check failed}}"
[INFO] Running build completed, took 14.6s

[INFO] Caching finalized dependency graph...
[INFO] Caching finalized dependency graph completed, took 58ms

[SEVERE] Failed after 14.7s
pub finished with exit code 1

I tried different things found out whenever I use the type VoidCallback or a generic type that has that type like Consumable<VoidCallback> as the method argument, code generation fails

@FatulM FatulM self-assigned this Aug 9, 2021
@FatulM
Copy link
Contributor

FatulM commented Aug 10, 2021

this will fail:

import 'package:sealed_annotations/sealed_annotations.dart';

part 'state.sealed.dart';

@Sealed()
abstract class _State {
  void one(void Function() x);
}
"SealedError{message={internal error},cause={check failed}}"

I think it's because of the internal checks I put on argument types which
I didn't think of function types as valid types!
😢

this will fail for the same reson:

import 'package:sealed_annotations/sealed_annotations.dart';

part 'state.sealed.dart';

typedef void ABC();

@Sealed()
abstract class _State {
  void one(ABC x);
}

for now you can use this workaround which won't fail:

import 'package:sealed_annotations/sealed_annotations.dart';

part 'state.sealed.dart';

typedef void ABC();

@Sealed()
abstract class _State {
  void one(@WithType('ABC') x);
}

I think analyzer unwraps typedefs by default,
but by using this workaround we are forcing dart_sealed to use typedef instead.

I should find a way to check functional types, then I can fix this issue.
@easazade

@FatulM FatulM changed the title code generation fails when using VoidCallback in sealed classes Functional types are not supported as field types Aug 10, 2021
@FatulM FatulM added bug Something isn't working good first issue Good for newcomers labels Aug 10, 2021
@easazade
Copy link
Contributor Author

@FatulM the solution worked fine

@FatulM
Copy link
Contributor

FatulM commented Aug 10, 2021

I've fixed this issue in 1.7.0,
Now you should be able to use all functional types,
check for example:
functional.dart

@easazade @SaeedMasoumi

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

No branches or pull requests

2 participants