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-3867] Improve diagnostics for labeled block without 'do' #46452

Closed
rintaro mannequin opened this issue Feb 6, 2017 · 3 comments
Closed

[SR-3867] Improve diagnostics for labeled block without 'do' #46452

rintaro mannequin opened this issue Feb 6, 2017 · 3 comments
Labels
compiler The Swift compiler in itself diagnostics QoI Bug: Diagnostics Quality of Implementation good first issue Good for newcomers improvement parser Area → compiler: The legacy C++ parser

Comments

@rintaro
Copy link
Mannequin

rintaro mannequin commented Feb 6, 2017

Previous ID SR-3867
Radar None
Original Reporter @rintaro
Type Improvement
Status Resolved
Resolution Done
Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Improvement, DiagnosticsQoI, Parser, StarterBug
Assignee mkita (JIRA)
Priority Medium

md5: 5e609ca6f870dca93d5db585edeaf041

Issue Description:

func foo(x: Int?) {
    LABEL: {
        guard let x = x else {
            break LABEL
        }
        print(x)
    }
    // ...
}

Currently, this results:

test.swift:2:8: error: consecutive statements on a line must be separated by ';'
  LABEL: {
       ^
       ;
test.swift:2:8: error: expected expression
  LABEL: {
       ^
test.swift:2:10: error: braced block of statements is an unused closure
  LABEL: {
         ^
test.swift:2:3: error: use of unresolved identifier 'LABEL'
  LABEL: {
  ^~~~~
test.swift:4:7: error: 'break' is only allowed inside a loop, if, do, or switch
      break LABEL
      ^
test.swift:2:10: error: expression resolves to an unused function
  LABEL: {
         ^

It would be great if it's diagnosed as a do statement with missing do keyword:

test.swift:2:10: error: labeled block needs 'do'
  LABEL: {
         ^
         do
@jtbandes
Copy link
Collaborator

jtbandes commented Feb 8, 2017

My recent changes improved this (it triggers closure expression is unused & did you mean to use a 'do' statement?) but there is still room for more improvement.

@belkadan
Copy link
Contributor

Resetting assignee for all Starter Bugs not modified since 2018.

@swift-ci
Copy link
Collaborator

Comment by Maksim Kita (JIRA)

Merged #29147

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
This issue was closed.
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 good first issue Good for newcomers improvement parser Area → compiler: The legacy C++ parser
Projects
None yet
Development

No branches or pull requests

3 participants