-
Notifications
You must be signed in to change notification settings - Fork 10.6k
Open
Labels
bugA deviation from expected or documented behavior. Also: expected but undesirable behavior.A deviation from expected or documented behavior. Also: expected but undesirable behavior.diagnostics QoIBug: Diagnostics Quality of ImplementationBug: Diagnostics Quality of Implementation
Description
Description
A compilation error inside a closure results in a misleading diagnostic.
Reproduction
func example(ptr: UnsafeRawPointer) {
let regions: [UnsafeRawBufferPointer] = []
let matchingRegion = regions.first { region in
let ptr = UInt(bitPattern: ptr)
return ptr >= UInt(bitPattern: region.baseAddress!)
&& ptr < (UInt(bitPattern: region.baseAddress!)
+ UInt(region.bogusProperty))
} // `bogusProperty` doesn't exist on UnsafeRawBufferPointer
}
See https://swift.godbolt.org/z/oTcq6McaE
The error message is:
<source>:3:34: error: cannot call value of non-function type 'UnsafeRawBufferPointer?'
1 | func example(ptr: UnsafeRawPointer) {
2 | let regions: [UnsafeRawBufferPointer] = []
3 | let matchingRegion = regions.first { region in
| `- error: cannot call value of non-function type 'UnsafeRawBufferPointer?'
4 | let ptr = UInt(bitPattern: ptr)
5 | return ptr >= UInt(bitPattern: region.baseAddress!)
Compiler returned: 1
Expected behavior
The error should be that bogusProperty
isn't a known property of UnsafeRawBufferPointer
.
Environment
Swift version 6.2-dev (LLVM 29f45403943bdc7, Swift 299f173)
swift-DEVELOPMENT-SNAPSHOT-2025-08-18-a (actually 6.3-dev)
Additional information
Note that using an inline closure rather than a trailing closure does not help.
same result:
func example(ptr: UnsafeRawPointer) {
let regions: [UnsafeRawBufferPointer] = []
let matchingRegion = regions.first(where: { region in
let ptr = UInt(bitPattern: ptr)
return ptr >= UInt(bitPattern: region.baseAddress!)
&& ptr < (UInt(bitPattern: region.baseAddress!)
+ UInt(region.bogusProperty))
} // `bogusProperty` doesn't exist on UnsafeRawBufferPointer
)
}
Credit to Noah Gregory https://swift-open-source.slack.com/archives/C04MRUD6VH8/p1755800748691209
Metadata
Metadata
Assignees
Labels
bugA deviation from expected or documented behavior. Also: expected but undesirable behavior.A deviation from expected or documented behavior. Also: expected but undesirable behavior.diagnostics QoIBug: Diagnostics Quality of ImplementationBug: Diagnostics Quality of Implementation