[SR-11155] Severely misleading type inference of closure argument #53552
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
type checker
Area → compiler: Semantic analysis
Additional Detail from JIRA
md5: 39662feb84c3367214be73ab8dc0749e
Issue Description:
I intentionally forgot the "contentsOf:" label when passing the closure argument, rawBuffer, into array append. This version of array append takes a single Element, UInt8, rather than a sequence of those elements.
I expect to get an error at the call to array.append, stating that UnsafeRawBufferPointer cannot be converted to UInt8.
Instead I get this error:
The type checker appears to be picking the wrong overload of withUnsafeBytes ❓ even though the argument type is explicitly provided. This is a problem because the diagnostic instructs the programmer to use the old deprecated API, potentially exposing undefined behavior.
Note that when I remove the closure argument type, I get this error:
"type of expression is ambiguous without more context"
Which prompts me to add the closure argument type. Never do I get an error pointing to the incorrect array.append call.
This problem isn't specific to array.append--that's just an easy way to demonstrate it. It seems to occur whenever the expression type checker fails to resolve something inside the closure...
The text was updated successfully, but these errors were encountered: