Skip to content

Report diagnostic on correct node#53538

Merged
RikkiGibson merged 8 commits intodotnet:mainfrom
Youssef1313:patch-12
May 20, 2021
Merged

Report diagnostic on correct node#53538
RikkiGibson merged 8 commits intodotnet:mainfrom
Youssef1313:patch-12

Conversation

@Youssef1313
Copy link
Member

@Youssef1313 Youssef1313 commented May 20, 2021

Fixes #53536
Fixes #50493

explicitcast

@ghost ghost added the Area-Compilers label May 20, 2021
@Youssef1313 Youssef1313 reopened this May 20, 2021
@Youssef1313 Youssef1313 marked this pull request as ready for review May 20, 2021 11:12
@Youssef1313 Youssef1313 requested a review from a team as a code owner May 20, 2021 11:12
@Youssef1313 Youssef1313 requested a review from a team as a code owner May 20, 2021 11:12
// (12,27): error CS0029: Cannot implicitly convert type 'System.Index' to 'int'
// Console.WriteLine(s[new Index(1, false), ^1]);
Diagnostic(ErrorCode.ERR_NoImplicitConv, "s[new Index(1, false), ^1]").WithArguments("System.Index", "int").WithLocation(12, 27));
Diagnostic(ErrorCode.ERR_NoImplicitConv, "^1").WithArguments("System.Index", "int").WithLocation(12, 27));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do the locations need to be updated too?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep I forgot those. Will update them shortly.

Copy link
Member

@davidwengier davidwengier left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @Youssef1313 😀

IDE test change LGTM

@AlekseyTs AlekseyTs added the Community The pull request was submitted by a contributor who is not a Microsoft employee. label May 20, 2021
// (11,17): error CS0656: Missing compiler required member 'System.Runtime.CompilerServices.RuntimeHelpers.GetSubArray'
// var x = arr[0..2];
Diagnostic(ErrorCode.ERR_MissingPredefinedMember, "arr[0..2]").WithArguments("System.Runtime.CompilerServices.RuntimeHelpers", "GetSubArray").WithLocation(11, 17));
Diagnostic(ErrorCode.ERR_MissingPredefinedMember, "0..2").WithArguments("System.Runtime.CompilerServices.RuntimeHelpers", "GetSubArray").WithLocation(11, 21));
Copy link
Contributor

@AlekseyTs AlekseyTs May 20, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Diagnostic

It looks like we are lacking test coverage for the following scenarios affected by the change:

  • pointer indexing
  • array creation
  • variable declaration with dimensions on the type #Closed

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • Will add a test for pointer indexing.

  • Array creation is covered in `CS0266ERR_NoImplicitConvCast13:

VerifyDiagnostics(
// (7,30): error CS0266: Cannot implicitly convert type 'double' to 'int'. An explicit conversion exists (are you missing a cast?)
// int[] arr4 = new int[x];// Invalid
Diagnostic(ErrorCode.ERR_NoImplicitConvCast, "x").WithArguments("double", "int").WithLocation(7, 30),
// (10,30): error CS0266: Cannot implicitly convert type 'float' to 'int'. An explicit conversion exists (are you missing a cast?)
// int[] arr5 = new int[y];// Invalid
Diagnostic(ErrorCode.ERR_NoImplicitConvCast, "y").WithArguments("float", "int").WithLocation(10, 30),
// (13,30): error CS0266: Cannot implicitly convert type 'decimal' to 'int'. An explicit conversion exists (are you missing a cast?)
// int[] arr6 = new int[z];// Invalid
Diagnostic(ErrorCode.ERR_NoImplicitConvCast, "z").WithArguments("decimal", "int").WithLocation(13, 30));

  • If you mean int[o] arr;, then this will produce error CS0270: Array size cannot be specified in a variable declaration (try initializing with a 'new' expression).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you mean int[o] arr;, then this will produce error CS0270: Array size cannot be specified in a variable declaration (try initializing with a 'new' expression).

Do we have an existing test demonstrating this with type mismatch in the illegal sizes?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@AlekseyTs If you mean something like:

    public void M(object o) {
        int[o] x;
    }

Then I think there is no test for it. I'll add it once you confirm this is the case you're requesting.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you mean something like ...

Yes, something like this. We want a test that hits your changes in BindArrayDimension for a variable declaration

@AlekseyTs
Copy link
Contributor

@Youssef1313 It looks like there are legitimate test failures.

@AlekseyTs
Copy link
Contributor

AlekseyTs commented May 20, 2021

Done with review pass (commit 4)


In reply to: 845142404

@AlekseyTs
Copy link
Contributor

AlekseyTs commented May 20, 2021

Done with review pass (commit 6)


In reply to: 845185257

Copy link
Contributor

@AlekseyTs AlekseyTs left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM (commit 8)

@AlekseyTs
Copy link
Contributor

@dotnet/roslyn-compiler For the second review.

@RikkiGibson RikkiGibson self-assigned this May 20, 2021
@RikkiGibson
Copy link
Member

Thanks for the contribution @Youssef1313!

@RikkiGibson RikkiGibson merged commit d513ddf into dotnet:main May 20, 2021
@ghost ghost added this to the Next milestone May 20, 2021
@Youssef1313 Youssef1313 deleted the patch-12 branch May 21, 2021 03:14
333fred added a commit that referenced this pull request May 24, 2021
…ures/interpolated-string

* upstream/main: (92 commits)
  Keep casts when necessary to prefer a constant pattern over a type pattern
  Remove SyntaxKind.DataKeyword (#53614)
  Display 'readonly' for record structs (#53634)
  Update Building, Debugging, and Testing on Windows.md (#53543)
  Update dependencies from https://github.com/dotnet/arcade build 20210521.3 (#53617)
  Introduce resx for BuildValidator and MS.CA.Rebuild to allow localization (#53447)
  Report obsoletion diagnostics for slice and indexer (#53463)
  Update BasicGenerateConstructorDialog.cs
  Add searchbox in generate overrides dialog
  Allow `with` on anonymous types (#53248)
  Report diagnostic on correct node (#53538)
  Fix NotNullIfNotNull delegate conversion (#53409)
  Verify quick info session in InvokeQuickInfo
  Remove unnecessary retry
  Ensure no navbar IO on the UI thread
  Enable nullable reference types
  Fix timeout behavior in GetQuickInfo
  Add a semantic model based GetQuickInfoAsync entry point into QuickInfoServiceWithProviders
  Move semantic model based quick info API up to CommonQuickInfoProvider type
  Fix dnceng build by forcing the use of xcopy msbuild
  ...
@RikkiGibson RikkiGibson modified the milestones: Next, 17.0.P2 Jun 29, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Area-Compilers Community The pull request was submitted by a contributor who is not a Microsoft employee.

Projects

None yet

4 participants