-
Notifications
You must be signed in to change notification settings - Fork 5.4k
Open
Description
The example below demonstrates a miscompilation on method resolution under "bool" context.
trait A { fn f() -> bool; }
impl A for u64 { fn f () -> bool { true } }
impl A for bool { fn f () -> bool { false } } // comment this line and everything will work
fn ff<T>() -> bool where T: A {
let v: bool = T::f();
v
}
fn main() {
if !(ff::<u64>()) { // we should return true, but we return false
__revert(0);
}
}
This last part, the context, seems to be important, because I think the problem lies at sway-core/src/semantic_analysis/type_check_context.rs:903
. We are trying to aid type inference using the expected type in the context.
But the generic argument is not in the return type, and so should not be affected by the context.
// Consider items from supersets indicated by the annotation return type.
if !matches!(&*type_engine.get(annotation_type), TypeInfo::Unknown) && !type_id.is_concrete(self.engines, crate::TreatNumericAs::Concrete) {
...
}
Metadata
Metadata
Assignees
Labels
No labels