Skip to content

Can`t mixin class with extended mixin #3484

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

Closed
ChaserVasya opened this issue Nov 27, 2023 · 4 comments
Closed

Can`t mixin class with extended mixin #3484

ChaserVasya opened this issue Nov 27, 2023 · 4 comments
Labels
request Requests to resolve a particular developer problem state-duplicate This issue or pull request already exists

Comments

@ChaserVasya
Copy link

ChaserVasya commented Nov 27, 2023

my helper file

import 'dart:async';
import 'package:bloc/bloc.dart';

mixin MyEventInterceptor<E, S> on _EventHandlerIntercepted<E, S> {
  S createErrorState(AppException e);

  @override
  _interceptor(handler, emit) async {
...
  }
}

mixin _EventHandlerIntercepted<Event, State> on Bloc<Event, State> {
  @override
  void on<E extends Event>(
    handler, {
    transformer,
  }) {
    return super.on(
      (event, emit) => _interceptor(() => handler(event, emit), emit),
      transformer: transformer,
    );
  }

  FutureOr<void> _interceptor(
    FutureOr<void> Function() handler,
    Emitter<State> emit,
  );
}

my bloc code

class MyBloc
    extends Bloc<MyEvent, MyState>
    with MyEventInterceptor<MyEvent,   MyState> {
...
}

error:

'MyEventInterceptor<MyEvent, MyState>' can't be mixed onto 'Bloc<MyEvent, MyState>' because 'Bloc<MyEvent, MyState>' doesn't implement '_EventHandlerIntercepted<MyEvent, MyState>'. (Documentation)  Try extending the class 'MyEventInterceptor<MyEvent, MyState>'.

dart 3.2.0

@ChaserVasya ChaserVasya added the feature Proposed language feature that solves one or more problems label Nov 27, 2023
@lrhn
Copy link
Member

lrhn commented Nov 27, 2023

That is working as currently specified.
As the error says, Bloc doesn't implement _EventHandlerIntercepted, so you cannot apply MyEventInterceptor to it.

If you're asking for this to work, then it's really a request for composite mixins, where MyEventInterceptor would somehow be declared as including the _EventHandlerIntercepted mixin, and mixing it in will apply both.
(That will require new syntax, the current declaration already has a specific meaning.)

There is an existing issue for mixin composition, #540, do we'll defer to that.

@lrhn lrhn added state-duplicate This issue or pull request already exists request Requests to resolve a particular developer problem and removed feature Proposed language feature that solves one or more problems labels Nov 27, 2023
@lrhn lrhn closed this as not planned Won't fix, can't repro, duplicate, stale Nov 27, 2023
@TekExplorer
Copy link

That is working as currently specified. As the error says, Bloc doesn't implement _EventHandlerIntercepted, so you cannot apply MyEventInterceptor to it.

If you're asking for this to work, then it's really a request for composite mixins, where MyEventInterceptor would somehow be declared as including the _EventHandlerIntercepted mixin, and mixing it in will apply both. (That will require new syntax, the current declaration already has a specific meaning.)

There is an existing issue for mixin composition, #540, do we'll defer to that.

Why would that need new syntax? wouldnt mixin [class] MyMixin with OtherMixin, Mixin2 {} be enough? It's a compiler error to do this now.

@lrhn
Copy link
Member

lrhn commented Dec 6, 2023

Well, that is new syntax, since a mixin or mixin class cannot have a with clause today.
It doesn't have to very different new syntax, preferably not, just some syntax which doesn't already have a meaning that we'd have to change.

@TekExplorer
Copy link

Well, that is new syntax, since a mixin or mixin class cannot have a with clause today. It doesn't have to very different new syntax, preferably not, just some syntax which doesn't already have a meaning that we'd have to change.

fair enough.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
request Requests to resolve a particular developer problem state-duplicate This issue or pull request already exists
Projects
None yet
Development

No branches or pull requests

3 participants