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

LineSplitter not assignable to Converter<String, List<String>> #28748

Closed
tvolkert opened this issue Feb 11, 2017 · 27 comments · Fixed by dart-archive/file.dart#62
Closed

LineSplitter not assignable to Converter<String, List<String>> #28748

tvolkert opened this issue Feb 11, 2017 · 27 comments · Fixed by dart-archive/file.dart#62
Labels
area-core-library SDK core library issues (core, async, ...); use area-vm or area-web for platform specific libraries. core-a library-convert P2 A bug or feature request we're likely to work on type-bug Incorrect behavior (everything from a crash to more subtle misbehavior)

Comments

@tvolkert
Copy link
Contributor

    Converter<String, List<String>> lineSplitter = const LineSplitter();

That line yields the following analyzer error:

[error] A value of type 'LineSplitter' can't be assigned to a variable of type 'Converter<String, List<String>>'

And yet, LineSplitter extends Converter<String, List<String>>

Huh??

@bwilkerson bwilkerson added area-analyzer Use area-analyzer for Dart analyzer issues, including the analysis server and code completion. P2 A bug or feature request we're likely to work on type-bug Incorrect behavior (everything from a crash to more subtle misbehavior) labels Feb 11, 2017
@leafpetersen
Copy link
Member

What version are you seeing this in? There was a temporary regression in the analyzer configuration logic that broke this, see here: #28507 .

This is fixed in bleeding edge, and I believe in more recent 1.22 dev releases. Closing the issues, but if you're seeing this in the latest dev release (or the next release candidate) please re-open.

@tvolkert
Copy link
Contributor Author

This was in 1.22.0-dev.9.1

@leafpetersen
Copy link
Member

Yes, it was broken in that dev release, fixed as of (at least) dev.10.1.

@tvolkert
Copy link
Contributor Author

Actually I'm still seeing this in 1.22.0-dev.10.6 -- see the failures in dart-archive/file.dart#38

@tvolkert
Copy link
Contributor Author

Still seeing this in 1.22.0-dev.10.6 (along with an inexplicable abundance of unawaited_futures false positive lint warnings, but that's a different issue).

I don't seem to have permission to re-open the issue; @leafpetersen, can you?

@leafpetersen leafpetersen reopened this Feb 13, 2017
@leafpetersen
Copy link
Member

I can reproduce. This was fixed from (at least) dev.10.1 through dev.10.3, but I see a regression again in dev.10.4 . As a workaround, you can use dev.10.3 for now.

@leafpetersen
Copy link
Member

Sorry, I didn't look through your original example closely enough. This is correct behavior. Linesplitter is not really type safe as originally written. To make it strong mode clean, the comment syntax was used to change its base class in strong mode.

class LineSplitter
    extends Converter<String, List<String>>/*=Object*/
    implements ChunkedConverter<String, List<String>, String, String>
        /*=StreamTransformer<String, String>*/ {

In strong mode, this is treated as extending Object.

So the error is correct, the regression was the temporary set of dev releases that used the old signature in strong mode.

@tvolkert
Copy link
Contributor Author

Linesplitter is not really type safe as originally written

@leafpetersen so is this code block even safe?

Converter<String, List<String>> lineSplitter =
    const LineSplitter() as Converter<String, List<String>>;

@leafpetersen
Copy link
Member

No. In strong mode that cast will fail. I believe that you can get from a StreamTransformer to a Converter via some path, but I'm not super familiar with the APIs here. @nex3 @kevmoo or @lrhn might be able to give some guidance.

@kevmoo
Copy link
Member

kevmoo commented Feb 14, 2017

@lrhn @floitschG Should really look at this.

Now that we've shipped generic syntax, this really should be cleaned up.

@tvolkert
Copy link
Contributor Author

I guess a meta-question is: can we make LineSplitter actually be a Converter<String, List<String>>?

@nex3
Copy link
Member

nex3 commented Feb 14, 2017

I guess a meta-question is: can we make LineSplitter actually be a Converter<String, List<String>>?

Not really. The Converter interface requires that the convert() method goes from S → T and that the bind() method goes from Stream<S> → Stream<T>. But LinesSplitter doesn't follow that. LineSplitter.convert() goes from String → List<String> (because it splits a single string into lines), whereas LineSplitter.bind() goes from Stream<String> → Stream<String> (because it splits lines across chunks).

Semantically speaking, I think LineSplitter is best modeled the way it's typed in strong mode right now: as a plain old StreamTransformer<String, String>. I'd even push for deprecating its existing convert() method since it's redundant with the static split() method.

@kevmoo
Copy link
Member

kevmoo commented Feb 14, 2017

What @nex3 said.

@lrhn @floitschG Reasonable?

@kevmoo kevmoo added area-core-library SDK core library issues (core, async, ...); use area-vm or area-web for platform specific libraries. library-convert S1 high and removed area-analyzer Use area-analyzer for Dart analyzer issues, including the analysis server and code completion. labels Feb 14, 2017
@floitschG
Copy link
Contributor

Yes.
That was the intention behind using the comment syntax. It is basically used as an ifdef for strong mode.

I don't think we should remove the convert method. LineSplitter isn't a converter anymore, but it definitely feels like one, and having similar APIs thus makes sense.

I would suggest closing this bug. We already have plans to completely remove the comment syntax which would make the transition from LineSplitter to a non-converter complete.

@kevmoo
Copy link
Member

kevmoo commented Feb 28, 2017

@floitschG but that will be a breaking change, right?

For which milestone?

@floitschG
Copy link
Contributor

When migrating to strong mode, programs need to adapt (but they need to do that anyway). After that there is no breaking change.

@srawlins
Copy link
Member

So it sounds like the resolution to this bug is changing LineSplitter's signature from:

class LineSplitter extends Converter<String, List<String>> /*=Object*/
    implements
        ChunkedConverter<String, List<String>, String, String>
/*=StreamTransformer<String, String>*/ {

to

class LineSplitter implements StreamTransformer<String, String> {

This is strange enough that I think it warrants its own bug (this bug, which blocks #28796 and #28773 rather than is a duplicate of), and warrants its own line in the CHANGELOG.

@kevmoo kevmoo added this to the 1.24 milestone Apr 19, 2017
@lrhn
Copy link
Member

lrhn commented Apr 24, 2017

Removing the comment syntax is a breaking change, which is why we were expecting to not do it until Dart 2.0. Until then, strong mode uses the Dart 2 signature and Dart 1 programs use the original one. It is annoying to maintain the comment syntax, and it would be great to not need it any more.
(There are other cases where comment syntax is still used for performance, but I believe this is the only one where removing it is a breaking change).

@kevmoo
Copy link
Member

kevmoo commented Apr 27, 2017

Are we saying this won't be in 1.24?

@floitschG floitschG removed this from the 1.24 milestone May 1, 2017
@floitschG
Copy link
Contributor

Removed the milestone. There is no reason to force this change. It will naturally happen once we discontinue support for comment syntax.

@lrhn
Copy link
Member

lrhn commented May 2, 2017 via email

@zoechi
Copy link
Contributor

zoechi commented May 4, 2017

Comment syntax was clearly communicated as experimental and
breaking changes in experimental features are expected and should be allowed?
It's always a great idea to try to avoid breakage of course, but what's the point of marking something experimental?
Just my 2c.

@lrhn
Copy link
Member

lrhn commented May 4, 2017

The problem here is that we don't just want to remove the comments, which would only be affecting the experimental version, but actually change the existing declaration to be the one that is currently in comments.
That breaks the existing, non-experimental version of the class, and any library that depends on it. It'll be a necessary change form Dart 2/Strong mode, but a breaking change for Dart 1. That's why we have been delaying the change.

@zoechi
Copy link
Contributor

zoechi commented May 4, 2017

I see. Thanks for clarification.

@nex3
Copy link
Member

nex3 commented Nov 22, 2017

I don't think this was actually supposed to be closed by dart-archive/file.dart#62.

@nex3 nex3 reopened this Nov 22, 2017
@leafpetersen
Copy link
Member

@nex3 I had actually intended to close this off, but am happy to keep it open if there's something actionable we still intend to do? As of now though, the use of the comment syntax in line_splitter.dart has been remove, LineSplitter works as you describe here: #28748 (comment) , and the original example from this issue is fixed.

@nex3
Copy link
Member

nex3 commented Nov 22, 2017

Oh okay, I just assumed that the "fixes" line in the file.dart commit accidentally closed this issue. It sounds like it was intentional, though, and I don't have anything else I think needs to be done.

@nex3 nex3 closed this as completed Nov 22, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-core-library SDK core library issues (core, async, ...); use area-vm or area-web for platform specific libraries. core-a library-convert P2 A bug or feature request we're likely to work on type-bug Incorrect behavior (everything from a crash to more subtle misbehavior)
Projects
None yet
Development

Successfully merging a pull request may close this issue.

9 participants