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

error: failed to produce diagnostic for expression #62519

Closed
gaultier opened this issue Dec 12, 2022 · 2 comments
Closed

error: failed to produce diagnostic for expression #62519

gaultier opened this issue Dec 12, 2022 · 2 comments
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself diagnostics QoI Bug: Diagnostics Quality of Implementation failed to produce diagnostic Bug → internal error: Failed to produce diagnostic for expression type checker Area → compiler: Semantic analysis

Comments

@gaultier
Copy link

Description
The compiler fails to build a simple one file program and halts with this error.

Steps to reproduce

import Foundation

var input = try! String(contentsOffile: CommandLine.arguments[1], encoding: String.Encoding.utf8)
let lines = input.split(separator: "\n")

for (_, line) in lines.enumerated() {
    print(line)
}

Command:

$ swiftc program.swift
/tmp/bug.swift:3:18: error: no exact matches in call to initializer
var input = try! String(contentsOffile: CommandLine.arguments[1], encoding: String.Encoding.utf8)
                 ^
Foundation.String:14:12: note: incorrect labels for candidate (have: '(contentsOffile:encoding:)', expected: '(contentsOfFile:encoding:)')
    public init(contentsOfFile path: __shared String, encoding enc: String.Encoding) throws
           ^
Foundation.String:23:12: note: incorrect labels for candidate (have: '(contentsOffile:encoding:)', expected: '(cString:encoding:)')
    public init?(cString: String, encoding enc: String.Encoding)
           ^
/tmp/bug.swift:6:1: error: failed to produce diagnostic for expression; please submit a bug report (https://swift.org/contributing/#reporting-bugs) and include the project
for (_, line) in lines.enumerated() {
^

Expected behavior

The source code is wrong since it should be contentsOfFile not contentsOffile as pointed out by the first error message, so that part is fine.

The issue is with the last error message.I am not sure why it gets printed, maybe nothing should be printed? Or unable to infer type for expression due to a previous error perhaps.

Environment

  • Swift compiler version info
swift-driver version: 1.62.15 Apple Swift version 5.7.1 (swiftlang-5.7.1.135.3 clang-1400.0.29.51)
Target: x86_64-apple-macosx12.0
  • Xcode version info
Xcode 14.1
Build version 14B47b
  • Deployment target: macOS 12.6.1

All done on the command line (no Xcode involved).

@gaultier gaultier added bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. triage needed This issue needs more specific labels labels Dec 12, 2022
@LucianoPAlmeida LucianoPAlmeida added compiler The Swift compiler in itself type checker Area → compiler: Semantic analysis failed to produce diagnostic Bug → internal error: Failed to produce diagnostic for expression and removed triage needed This issue needs more specific labels labels Dec 12, 2022
@LucianoPAlmeida
Copy link
Contributor

I think this was fixed by #60062
Can you verify using the latest snapshot from main and close? Thanks

@gaultier
Copy link
Author

Confirmed to be fixed with

$ xcrun -sdk macosx  ../build/Ninja-RelWithDebInfoAssert/swift-macosx-x86_64/bin/swiftc --version
Swift version 5.8-dev (LLVM 18bbb58dec87a5a, Swift 4ca5d1e7ee533c5)
Target: x86_64-apple-macosx12.0

It outputs with the sample program from above:

/Users/pgaultier/scratch/bug.swift:3:18: error: no exact matches in call to initializer
var input = try! String(contentsOffile: CommandLine.arguments[1], encoding: String.Encoding.utf8)
                 ^
Foundation.String:14:12: note: incorrect labels for candidate (have: '(contentsOffile:encoding:)', expected: '(contentsOfFile:encoding:)')
    public init(contentsOfFile path: __shared String, encoding enc: String.Encoding) throws
           ^
Foundation.String:23:12: note: incorrect labels for candidate (have: '(contentsOffile:encoding:)', expected: '(cString:encoding:)')
    public init?(cString: String, encoding enc: String.Encoding)

@AnthonyLatsis AnthonyLatsis added the diagnostics QoI Bug: Diagnostics Quality of Implementation label Dec 22, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself diagnostics QoI Bug: Diagnostics Quality of Implementation failed to produce diagnostic Bug → internal error: Failed to produce diagnostic for expression type checker Area → compiler: Semantic analysis
Projects
None yet
Development

No branches or pull requests

3 participants