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-13429] Diagnostic improvement: Provide more contextual information in case of an overflow error #55870

Open
typesanitizer opened this issue Aug 21, 2020 · 2 comments
Labels
compiler The Swift compiler in itself diagnostics QoI Bug: Diagnostics Quality of Implementation improvement type checker Area → compiler: Semantic analysis

Comments

@typesanitizer
Copy link

Previous ID SR-13429
Radar rdar://problem/67559979
Original Reporter @typesanitizer
Type Improvement
Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Improvement, DiagnosticsQoI, TypeChecker
Assignee None
Priority Medium

md5: 0d308c31e3a44c16b6f79d7ad6cf40d5

Issue Description:

If you have code like:

struct S {
   init(_: UInt8) {}
   init?(_: Int) {}
}

let _: S = S(9999) // error: integer literal '9999' overflows when stored into 'UInt8'

If the user doesn't fully understand how type inference is working, this might be confusing (they might think that the Int overload ought to be called). For example, this can lead to potentially surprising behavior around Unicode.Scalar as in SR-13407.

It would be helpful in such a situation to point out the overload being used. To characterize the situation properly, here's when I'd expect this contextual information to kick in:

  1. The error is due to overflow.

  2. There are "similar" methods (e.g. other overloads or other initializers) for which the overflow would not happen.

If 2. is too difficult to implement, maybe we can special-case the single-argument initializer situation to address the Unicode.Scalar case and handle more complex situations later based on bug reports.

@typesanitizer
Copy link
Author

@swift-ci create

@theblixguy
Copy link
Collaborator

This comes from SIL diagnostics so I think (2) would be tricky, not fully sure about (1) though (inlining/@_transparent and other optimizations might lead to the init call not being present, just its body), but I believe since diagnostic comes from constant propagation pass it might be feasible to do (1) as that pass is run quite early.

@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 type checker Area → compiler: Semantic analysis
Projects
None yet
Development

No branches or pull requests

2 participants