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

"Create missing overrides" fix creates incorrect linkedEditGroups, causing invalid code #41147

Closed
DanTup opened this issue Mar 23, 2020 · 4 comments
Labels
analyzer-quick-fix area-analyzer Use area-analyzer for Dart analyzer issues, including the analysis server and code completion.

Comments

@DanTup
Copy link
Collaborator

DanTup commented Mar 23, 2020

Moving this from Dart-Code/Dart-Code#2307 as it looks like a server issue. I can repro in both VS Code and Android Studio, though only in a Flutter project, not using the Dart SDK directly (I can't explain this bit, but I tried with a few recent Flutter SDKs and the latest dev + nightly Dart SDK, and it occurred only in the Flutter projects).

In a Flutter project, create a file with the following code:

import 'package:meta/meta.dart';

class MyTestClass {
  void verifyPhoneNumber({
    @required String phoneNumber,
    @required Duration timeout,
  }) {}

  Future<void> signInWithCustomToken({@required String token}) async {}
}

class A implements MyTestClass {}

Invoke "create 2 missing overrides" on class A and you'll end up with code like:

class A implements MyTestClass {
  @override
  Future<void> signInWithCustomToken({String token}) {
      // TODO: implement signInWithCustomToken
      throw UnimplementedError();
    }
  
    @override
    void verifyPhoneNumber({String token}) {      // <-- these last few characters are invalid
   , Duration timeout}) {
    // TODO: implement verifyPhoneNumber
  }
}

Screenshot 2020-03-23 at 12 17 02

This seems to occur, because linkedEditGroups are generated that bundle String from both methods together, and also the arguments token and phoneNumber together - but they have only a single length per group, so the length of phoneNumber is applied to token which results in some unwanted characters:

{
	"positions": [
		{
			"file": "/Users/danny/Dev/Google/flutter/examples/flutter_gallery/lib/2307.dart",
			"offset": 321
		},
		{
			"file": "/Users/danny/Dev/Google/flutter/examples/flutter_gallery/lib/2307.dart",
			"offset": 458
		}
	],
	"length": 11,     // This 11 is only correct for one of the offsets above, the other has a length of 6
	"suggestions": []
},

Screenshot 2020-03-23 at 12 01 20

@mit-mit mit-mit added the area-analyzer Use area-analyzer for Dart analyzer issues, including the analysis server and code completion. label Mar 23, 2020
@DanTup
Copy link
Collaborator Author

DanTup commented May 9, 2020

Hit this with a simpler repro today. What I can't figure out, is why it only occurs in a Flutter project. If I use the exact same Dart SDK (from the flutter/bin/cache/dart-sdk) in a Dart project, it generates the correct code.

class Foo extends Bar {}

abstract class Bar {
  void update(double t);
  void render(String c);
}

Run "Create missing overrides" on Foo, and in a Flutter project it'll use String for both args but in a Dart project it'll correctly use double for one of them.

@DanTup
Copy link
Collaborator Author

DanTup commented Jun 11, 2020

@bwilkerson this seems to be coming up quite a bit lately - not sure if you've seen this though, as it hasn't been tagged as much as other analyzer issues.

I haven't been able to figure out why it only seems to happen in Flutter projects, doesn't seem like that should affect something like this.

@DanTup
Copy link
Collaborator Author

DanTup commented Jul 6, 2020

This has been fixed (#42468).

@DanTup DanTup closed this as completed Jul 6, 2020
@proninyaroslav
Copy link

proninyaroslav commented Jul 8, 2020

Also encountered this problem (VSCode).

class ShipmentActivityInfo {}

abstract class ShipmentRepository {
  Future<void> addActivities(List<ShipmentActivityInfo> activities);

  Future<void> deleteActivitiesByTrack(String trackNumber);

  Future<List<ShipmentActivityInfo>> getActivitiesByTrack(String trackNumber);
}

class ShipmentRepositoryImpl extends ShipmentRepository {}

Peek 2020-07-08 11-25

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
analyzer-quick-fix area-analyzer Use area-analyzer for Dart analyzer issues, including the analysis server and code completion.
Projects
None yet
Development

No branches or pull requests

4 participants