Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

instanceof returns True in cases where the requested class is not accessible #1191

Closed
davidnich opened this issue Aug 28, 2016 · 1 comment
Closed

Comments

@davidnich
Copy link
Contributor

instanceof should return False for privately-inherited base classes when the requested class is not accessible; in such cases the API requested with instanceof is not actually available

@davidnich davidnich added this to the 0.8.13 milestone Aug 28, 2016
@davidnich davidnich changed the title instanceof returns True for in cases where the requested class is not accessible instanceof returns True in cases where the requested class is not accessible Aug 30, 2016
@omusil24
Copy link

Current status:

#!/usr/bin/env qore
# -*- mode: qore; indent-tabs-mode: nil -*-

%new-style
%enable-all-warnings
%require-types
%strict-args

%requires QUnit

%exec-class QUnitTest

class A inherits public X {
    constructor() : X() {}
}

class B inherits private X {
    constructor() : X() {}
}

class C inherits private:internal X {
    constructor() : X() {}
}

class X {
}

public class QUnitTest inherits QUnit::Test {
    constructor() : Test("QUnitTest", "1.0") {
        addTestCase("test", \testMethod(), NOTHING);

        # Return for compatibility with test harness that checks return value.
        set_return_value(main());
    }

    testMethod() {
        A a();
        B b();
        C c();

        assertTrue(a instanceof A);
        assertTrue(b instanceof B);
        assertTrue(c instanceof C);

        # OK
        assertTrue(a instanceof X);

        # prints INVALID-OPERATION: 'object<B> instanceof object<X>' always returns False
        assertFalse(b instanceof X);

        # prints INVALID-OPERATION: 'object<C> instanceof object<X>' always returns False
        assertFalse(c instanceof X); # prints INVALID-OPERATION warning
    }
}

Therefore I'd say this bug is fixed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants