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

[SR-13256] Diagnostic is not consistent with changing source code #55696

Open
swift-ci opened this issue Jul 20, 2020 · 2 comments
Open

[SR-13256] Diagnostic is not consistent with changing source code #55696

swift-ci opened this issue Jul 20, 2020 · 2 comments
Labels
compiler The Swift compiler in itself diagnostics QoI Bug: Diagnostics Quality of Implementation improvement

Comments

@swift-ci
Copy link
Collaborator

Previous ID SR-13256
Radar None
Original Reporter srinikhil07 (JIRA User)
Type Improvement
Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Improvement, DiagnosticsQoI
Assignee None
Priority Medium

md5: 1babd992aab85f7829f313bfbec1447e

Issue Description:

Hi team,

The below line produces the expected diagnostic

var graph = Dictionary<Int,[Int]>

expected member name or constructor call after type name

I didn't notice this diagnostic in VSCode (where errors aren't highlighted enough) I continued with the below code. The diagnostic for Dictionary initialization is changed now

var graph = Dictionary<Int,[Int]> 
for element in graph {
} 

type of expression is ambiguous without more context

I further modified code below to having a for loop with completely independent expression

let arr = [String]()
var graph = Dictionary<Int,[Int]>
for element in arr {
}

which produces again the same diagnostic

type of expression is ambiguous without more context

Shouldn't the diagnostic be consistent for a line not changed (here Dictionary initialization) despite surrounding lines changing and that too not related to the initialization in question?

@theblixguy
Copy link
Collaborator

For the following example you mentioned above:

var graph = Dictionary<Int,[Int]> 
for element in graph {
} 

I get (on master):

/Users/spare/Desktop/test.swift:1:28: error: expected pattern
var graph = Dictionary<Int,[Int]>
                           ^
/Users/spare/Desktop/test.swift:1:23: error: binary operator '<' cannot be applied to operands of type 'Dictionary<_, _>.Type' and 'Int.Type'
var graph = Dictionary<Int,[Int]>
            ~~~~~~~~~~^~~~
/Users/spare/Desktop/test.swift:1:13: error: generic parameter 'Key' could not be inferred
var graph = Dictionary<Int,[Int]>
            ^
/Users/spare/Desktop/test.swift:1:13: note: explicitly specify the generic arguments to fix this issue
var graph = Dictionary<Int,[Int]>
            ^
                      <<#Key: Hashable#>, Any>

and for:

let arr = [String]()
var graph = Dictionary<Int,[Int]>
for element in arr {
}

I get this (on master):

/Users/spare/Desktop/test.swift:2:28: error: expected pattern
var graph = Dictionary<Int,[Int]>
                           ^
/Users/spare/Desktop/test.swift:2:23: error: binary operator '<' cannot be applied to operands of type 'Dictionary<_, _>.Type' and 'Int.Type'
var graph = Dictionary<Int,[Int]>
            ~~~~~~~~~~^~~~
/Users/spare/Desktop/test.swift:2:13: error: generic parameter 'Key' could not be inferred
var graph = Dictionary<Int,[Int]>
            ^
/Users/spare/Desktop/test.swift:2:13: note: explicitly specify the generic arguments to fix this issue
var graph = Dictionary<Int,[Int]>
            ^
                      <<#Key: Hashable#>, Any>
/Users/spare/Desktop/test.swift:3:5: warning: immutable value 'element' was never used; consider replacing with '_' or removing it
for element in arr {
    ^~~~~~~
    _

@swift-ci
Copy link
Collaborator Author

Comment by Nikhil (JIRA)

@theblixguy

Thanks for looking.

Yes, I get the same in master. I have some doubts.

I am not understanding the diagnostic produced (on master) and I am not sure if its right/wrong.

Also, isn't the diagnostic (on master) a bit overwhelming?

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
compiler The Swift compiler in itself diagnostics QoI Bug: Diagnostics Quality of Implementation improvement
Projects
None yet
Development

No branches or pull requests

2 participants