diff --git a/src/compiler.rs b/src/compiler.rs index 49f6eda..eeb5caf 100644 --- a/src/compiler.rs +++ b/src/compiler.rs @@ -513,7 +513,16 @@ impl Compiler { // simple interning - try to find a constant that is exactly equal to this one and just // return its value instead for (index, interned) in self.constants.iter().enumerate() { - if constant.borrow().equals(&*interned.borrow()) { + // check if the two objects are the same type. If they are not, this can cause an + // interesting bug where two objects that are different types are considered equal. The + // best example is a Float(1.0) and Int(1) are considered equal. + if constant + .borrow() + .ty() + .borrow() + .equals(&*interned.borrow().ty().borrow()) + && constant.borrow().equals(&*interned.borrow()) + { return Ok(index as ConstantId); } }