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 with optionals and generics (minimal repro) #64238

Open
tristanlabelle opened this issue Mar 9, 2023 · 3 comments
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler itself expressions Feature: expressions failed to produce diagnostic Bug → internal error: Failed to produce diagnostic for expression generics Feature: generic declarations and types swift 5.9 type checker Area → compiler: Semantic analysis type inference Feature: type inference unexpected error Bug: Unexpected error

Comments

@tristanlabelle
Copy link
Contributor

Description
The Swift compiler produces a fatal error when compiling a combination of generics and optionals.

Steps to reproduce
Compile the following with swiftc:

class Repro {
    func foo(repro: Repro?) { _ = repro?.bar() }
    func bar<T>() -> T { fatalError("") }
}

Output:

Building for debugging...
C:\Code\browser-swift\Apps\BrowserWin\Source\Application\ArcApplication.swift:2:33: error: failed to produce diagnostic for expression; please submit a bug report (https://swift.org/contributing/#reporting-bugs)
    func foo(repro: Repro?) { _ = repro?.bar() }
                                ^
error: fatalError

Expected behavior
A diagnostic should be produced and the compiler should not fatalError

Environment

  • Swift compiler version info: February 27, 2023 snapshot on Windows
compnerd.org Swift version 5.9-dev (LLVM 84aca0981812b32, Swift a0e1810f627add5)
Target: x86_64-unknown-windows-msvc
  • Xcode version info: N/A
  • Deployment target: N/A
@tristanlabelle tristanlabelle added bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. triage needed This issue needs more specific labels labels Mar 9, 2023
@xedin xedin added type checker Area → compiler: Semantic analysis crash Bug: A crash, i.e., an abnormal termination of software and removed triage needed This issue needs more specific labels labels Mar 9, 2023
@xedin
Copy link
Contributor

xedin commented Mar 9, 2023

Looks like we binding type variable allocated for optional evaluation expression to the one that represents generic parameter and that ends up propagating "can be hole" trait to the former one without a fix.

@xedin
Copy link
Contributor

xedin commented Mar 9, 2023

cc @LucianoPAlmeida maybe interesting, I wonder if we need to change constraint generation for optional evaluation expression slightly to avoid this kind of problem.

@AnthonyLatsis AnthonyLatsis added compiler The Swift compiler itself failed to produce diagnostic Bug → internal error: Failed to produce diagnostic for expression expressions Feature: expressions swift 5.9 unexpected error Bug: Unexpected error generics Feature: generic declarations and types type inference Feature: type inference and removed crash Bug: A crash, i.e., an abnormal termination of software labels Mar 9, 2023
@LucianoPAlmeida
Copy link
Contributor

I remember this one, is the propagation logic we have for optional evaluation right?
Was taking a look at the comment and it was mainly for pattern context, but now that pattern variables are marked as holes this propagation is still needed? Maybe I am missing something or it still needed in general.
What is the idea on adjusting CSGen logic?

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 itself expressions Feature: expressions failed to produce diagnostic Bug → internal error: Failed to produce diagnostic for expression generics Feature: generic declarations and types swift 5.9 type checker Area → compiler: Semantic analysis type inference Feature: type inference unexpected error Bug: Unexpected error
Projects
None yet
Development

No branches or pull requests

4 participants