Menu

#871 Inherited methods without this shadowed by global functions

closed
nobody
None
compiler
2021-10-03
2017-10-28
dkl
No

It seems like calling foo() without explicit this will prefer a global foo() over an inherited method foo():

sub f()
    print "f"
end sub

type A
    i as integer
    declare sub f()
end type

sub A.f()
    print "A.f"
end sub

type B extends A
    declare sub test()
end type

sub B.test()
    f()
end sub

dim bb as B
bb.test()
Prints:
f
Expected:
A.f

I think it should prefer the inherited method, since the this is implicit inside methods. The global should be reachable through the special . operator for accessing the global namespace instead.

Related

Bugs: #730

Discussion

  • dkl

    dkl - 2017-10-28
    • Description has changed:

    Diff:

    --- old
    +++ new
    @@ -1,4 +1,4 @@
    -It seems like calling foo() without explicit this will prefer a global foo() over a method foo():
    +It seems like calling foo() without explicit `this` will prefer a global foo() over a method foo():
     ```
     sub f()
         print "f"
    
     
  • dkl

    dkl - 2017-10-28
    • Description has changed:

    Diff:

    --- old
    +++ new
    @@ -25,4 +25,11 @@
     bb.test()
     ```
    
    +```
    +Prints:
    +f
    +Expected:
    +A.f
    +```
    +
     I think it should prefer the method, since the `this` is implicit inside methods. The global should be reachable through the special `.` operator for accessing the global namespace instead.
    
     
  • dkl

    dkl - 2017-10-28
    • summary: Methods without this shadowed by global functions --> Inherited methods without this shadowed by global functions
    • Description has changed:

    Diff:

    --- old
    +++ new
    @@ -1,4 +1,4 @@
    -It seems like calling foo() without explicit `this` will prefer a global foo() over a method foo():
    +It seems like calling foo() without explicit `this` will prefer a global foo() over an inherited method foo():
     ```
     sub f()
         print "f"
    @@ -32,4 +32,4 @@
     A.f
     ```
    
    -I think it should prefer the method, since the `this` is implicit inside methods. The global should be reachable through the special `.` operator for accessing the global namespace instead.
    +I think it should prefer the inherited method, since the `this` is implicit inside methods. The global should be reachable through the special `.` operator for accessing the global namespace instead.
    
     
  • dkl

    dkl - 2017-10-28

    possibly related: [#581], [#645]

     

    Related

    Bugs: #581
    Bugs: #645

  • Jeff Marshall

    Jeff Marshall - 2021-10-02

    First look at this bug and we certainly find it's in the same area of the compiler as [#645] and [#581]. The cause is a little different.

    Changing the order of the functions in the original example source produces the correct look-up:

    type A
        i as integer
        declare sub f()
    end type
    
    sub A.f()
        print "A.f"
    end sub
    
    type B extends A
        declare sub test()
    end type
    
    sub B.test()
        f()
    end sub
    
    sub f()
        print "f"
    end sub
    
    dim bb as B
    bb.test()
    
    /'
    Prints:
    A.f
    Expected:
    A.f
    '/
    

    We are getting the correct symbols on the symbol chain when it is looked up in the symbol database, but in this scenario we should not expect the called function to be dependent on the order of definition. And causes a problem of not being able to call ..f() from B.test() because then there is no way to declare the global f() procedure before it is referenced.

     

    Related

    Bugs: #581
    Bugs: #645

  • Jeff Marshall

    Jeff Marshall - 2021-10-03
    • status: open --> closed
     

Log in to post a comment.

MongoDB Logo MongoDB