I had a useable stdlib that just contained the implementation of Int, some pointers, Optional, Bool and other similar, low level things (no strings, arrays, etc.)
When I upgraded the compiler to 5.0 I'm getting weird errors in my test code compiled against this now. It's like it doesn't recognise + any more, despite the fact it's definitely in my Swift.swift (minimal stdlib) file and that has compiled to a module without error.
Even more weird, this code still shows the same error:
import Swift
infix operator +
extension Int {
static func +(lhs: Int, rhs: Int) -> Int {
return lhs
}
}
let i: Int = 3
while true {
var j: Int = i + 9
}
I still get the error that the operator is not recognised. (I don't have the exact error here, I'll post it tonight.)
...what effect do the protocol names after the precedence specifier have? Could that be interfering with parsing the + operator correctly in my code somehow?
(p.s. In my version I'm just doing... infix operator + : AdditionPrecedence, AdditiveArithmetic ...because I don't have the other protocols defined.)
Is your custom stdlib available somewhere that we could try building it and see the error ourselves? I can't guarantee exactly when I'll have time to do so, but if you can point me to it I'll try to take a look.
@jroseparsing Mark's thing is off by default too, right? So if @carlos42421 has a designated protocol in the operator declaration, either he's building with at least that piece enabled (and so maybe the other piece too?) or the operator declaration may not be getting parsed (but I would expect an error then?)
main.swift:1:8: warning: implicit import of bridging header 'AVR.h' via module 'AVR' is deprecated and will be removed in a later version of Swift
import AVR
^
main.swift:28:18: error: use of unresolved operator '+'
var v: Int = i + 9
^
make: *** [main.ll] Error 1
Also I sort of expected a different error message in that case, like Int does not implement the + operator or something? Maybe what I'm not clear on is what does unresolved operator mean? Does it mean "there's no definition for that operator" or does it mean "I cannot find an overload for that operator that fits these type constraints in this expression" type of thing? Sorry if I'm asking dumb questions.
public static func +(lhs: Int, rhs: Int) -> Int {
return lhs
}
And now it's working.
So it looks like the error message means something more like, "I know that + is an operator with this associativity and precedence, but I can't find an implementation that matches the type constraints in this expression".
I’ll make sure it’s not just a side effect of my crazy stdlib first. Then raise one if it seems to be a general issue. Otherwise it’s just a problem in my odd little world. Ha.