Misleading errors when chaining correct code with incorrect code. #74617
Labels
bug
A deviation from expected or documented behavior. Also: expected but undesirable behavior.
compiler
The Swift compiler itself
diagnostics QoI
Bug: Diagnostics Quality of Implementation
expressions
Feature: expressions
operators
Feature: operators
swift 6.0
type checker
Area → compiler: Semantic analysis
Description
No response
Reproduction
Here's an example:
I make 2 instances of
Foo
and then add them together using the+
operator. The issue here is that then, I (accidentally) calledbar()
when in fact,bar
is just a field - and the compiler threw these 2 errors:Both of those are confusing to me:
+
operator is clearly defined forFoo
and botha
andb
areFoo
, so why does it complain that this operator can not be applied?+
isFoo
, so why does it say thatbar
is not a member ofNever
?Additionally, I had a case (I'll try to recreate it later) where the LSP was only showing the 1st error and I spent a lot of time trying to understand why it says that I can't use
+
when it is clearly implemented before I figured out what the real issue was.If I make split all those calls instead of chaining them...
... then I get a more appropriate error:
Expected behavior
The compiler should not complain about not being able to apply the
+
operator, but only about the fact thatbar
is not a function.Environment
Apple Swift version 6.0-dev (LLVM de395d39a90ed7a, Swift 490cf64)
Target: arm64-apple-macosx14.0
Additional information
No response
The text was updated successfully, but these errors were encountered: