For the following test, I wish the compiler error say the actual problem:
"Cannot apply / on or between Numeric"
funcfooAAA<T : Numeric>(_a: T, _b: T) -> T {
// this results in two compile errors, first is correct, second should not be:// Binary operator '/' cannot be applied to operands of type 'T' and 'Int' <=== this error is correct// Binary operator '+' cannot be applied to two 'T' operands <=== !!! but this should not be an error!!!
(a + b) / 2
}
// this version returns void, now the same expression give different compiler errorfuncfooDDD<T : Numeric>(_a: T, _b: T) {
// same expression but give different error:// Cannot convert value of type 'T' to expected argument type 'Int'// Replace '(a + b)' with 'Int((a + b))'// so the compiler give totally different diagnostic for the same expression as above
(a + b) / 2
}
Breaking the expression up produce better error:
letsum = a + breturnsum / 2// Binary operator '/' cannot be applied to operands of type 'T' and 'Int'
Additional Detail from JIRA
md5: d9ae95cc29673bbed4806ff8fa1380ca
Issue Description:
For the following test, I wish the compiler error say the actual problem:
"Cannot apply / on or between Numeric"
Breaking the expression up produce better error:
see: https://forums.swift.org/t/unhelpful-inconsistent-compiler-error/51092
The text was updated successfully, but these errors were encountered: