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

failed to produce diagnostic for ... a range expression #72533

Open
shin-ckane opened this issue Mar 22, 2024 · 1 comment
Open

failed to produce diagnostic for ... a range expression #72533

shin-ckane opened this issue Mar 22, 2024 · 1 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 expressions Feature: expressions for-in loops Feature: for-in loops generics Feature: generic declarations and types internal error Bug: Internal error operators Feature: operators statements Feature: statements swift 6.0 type checker Area → compiler: Semantic analysis

Comments

@shin-ckane
Copy link

Description

% swift coord.swift 
coord.swift:8:9: error: failed to produce diagnostic for expression; please submit a bug report (https://swift.org/contributing/#reporting-bugs)
        for b in Int(minB) ..< ValueType.max {
        ^

when the left-hand side of the range operator was changed from 0 to Int(minB).

Reproduction

struct Coord {

    private typealias ValueType = Int16

    init<T>(clamping value: T) where T : BinaryInteger {
        let minB = (Double(value - T(ValueType.max)) / 3.0).rounded(.down)
        for b in Int(minB) ..< ValueType.max {

        }
        fatalError("TODO")
    }

}

Stack dump

none

Expected behavior

The rhs to the range operator is of type Int16. If that is changed to Int(ValueType.max), to match the type of the lhs, problem goes away.
Is "failed to produce diagnostic" the best diagnostic the compiler can produce to explain what is wrong with the source code?

Environment

% swift -version
swift-driver version: 1.90.11.1 Apple Swift version 5.10 (swiftlang-5.10.0.13 clang-1500.3.9.4)
Target: arm64-apple-macosx14.0

Additional information

No response

@shin-ckane shin-ckane added bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. crash Bug: A crash, i.e., an abnormal termination of software triage needed This issue needs more specific labels labels Mar 22, 2024
@AnthonyLatsis AnthonyLatsis added internal error Bug: Internal error compiler The Swift compiler in itself type checker Area → compiler: Semantic analysis for-in loops Feature: for-in loops statements Feature: statements operators Feature: operators expressions Feature: expressions diagnostics QoI Bug: Diagnostics Quality of Implementation swift 6.0 and removed crash Bug: A crash, i.e., an abnormal termination of software triage needed This issue needs more specific labels labels Mar 22, 2024
@AnthonyLatsis
Copy link
Collaborator

Reduction:

func test() {
  let int: Int
  let int16: Int16
  // error: type of expression is ambiguous without a type annotation
  _ = Int(int) ..< int16
  // Expected error:
  // error: conflicting arguments to generic parameter 'Self' ('Int' vs. 'Int16') [conflicting_arguments_for_generic_parameter]
  _ = int ..< int16
}

@AnthonyLatsis AnthonyLatsis added the generics Feature: generic declarations and types label Mar 22, 2024
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 expressions Feature: expressions for-in loops Feature: for-in loops generics Feature: generic declarations and types internal error Bug: Internal error operators Feature: operators statements Feature: statements swift 6.0 type checker Area → compiler: Semantic analysis
Projects
None yet
Development

No branches or pull requests

2 participants