type field ambiguity (possbile bug)

General FreeBASIC programming questions.
sancho3
Posts: 358
Joined: Sep 30, 2017 3:22

type field ambiguity (possbile bug)

Postby sancho3 » Feb 26, 2019 8:39

If a child type method local variable shares the same name as a parent member field it blocks access to the parent field.
I think this could be a bug. I searched the bug reports and can't find anything.
Here is an example:

Code: Select all

Type parent 
   As Integer x1, y1, x2, y2
End Type
Type child Extends parent
   Declare Sub foo()
End Type
   Sub child.foo()
      with This
         Dim As Integer x1, y1, x2, y2
         Dim as integer zx1 
         'x1 = .x1       ' error: element not defined
         'x1 = this.x1   ' error: element not defined
         zx1 = .x1      ' this will error as well unless you comment out the first dim as line
      end With
   End Sub
fxm
Posts: 10037
Joined: Apr 22, 2009 12:46
Location: Paris suburbs, FRANCE

Re: type field ambiguity (possbile bug)

Postby fxm » Feb 26, 2019 9:28

Related to the bug already reported a long time ago (2013-01-05):
#645 Access to global duplicated symbol is captured by local symbol
(#581 Locals break/override THIS access to inherited members)

A workaround exists in this precise case:
x1 = Base.x1
sancho3
Posts: 358
Joined: Sep 30, 2017 3:22

Re: type field ambiguity (possbile bug)

Postby sancho3 » Feb 28, 2019 6:17

Yes that is the bug. I saw bug #645 in my search but I didn't think it was related.
Now that I read the comments I see that it is the same.
It is a bug that is not likely to be fixed, but as you point out its not a difficult workaround.

Return to “General”

Who is online

Users browsing this forum: No registered users and 9 guests