Fix lookups in ObjectMirror.implements_trait?

This method would mistakingly keep looking up traits in the mirror
subject, instead of using the objects in the prototype chain.
parent e33ed34f
Pipeline #40708593 passed with stages
in 14 minutes and 4 seconds
......@@ -267,7 +267,7 @@ object ObjectMirror {
let mut subject = @subject
{
let traits = _INKOC.get_attribute(@subject, IMPLEMENTED_TRAITS_ATTRIBUTE)
let traits = _INKOC.get_attribute(subject, IMPLEMENTED_TRAITS_ATTRIBUTE)
traits.if_true {
_INKOC.get_attribute(traits, find).if_true {
......
......@@ -6,6 +6,7 @@ import std::mirror::(
)
import std::test
import std::test::assert
import std::trait::(self as trait_mod)
let CURRENT_FILE = ModuleMirror.new(ThisModule).path
......@@ -152,6 +153,17 @@ test.group('std::mirror::ObjectMirror.implements_trait?') do (g) {
assert.true(mirror.implements_trait?(Trait1))
}
g.test('Checking if a parent implements a trait for a child with custom implementations') {
let obj = Dummy.new
let mirror = ObjectMirror.new(obj)
trait_mod.implement(implement_for: obj, to_implement: Trait2)
assert.true(mirror.implements_trait?(Trait1))
assert.true(mirror.implements_trait?(Trait2))
assert.false(ObjectMirror.new(Dummy).implements_trait?(Trait2))
}
g.test('Checking if Nil implements a trait') {
let mirror = ObjectMirror.new(Nil)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment