[Gambas-user] Issue 78 in gambas: Illegal optimization / May a method's return value type in a derived class be different from the base class?

gambas at ...2524... gambas at ...2524...
Thu Aug 11 15:44:22 CEST 2011


Status: New
Owner: ----
Labels: Version Type-Bug Priority-Medium OpSys-Any Dist-Any Arch-Any  
Desktop-Any GUI-Any

New issue 78 by emil.len... at ...626...: Illegal optimization / May a  
method's return value type in a derived class be different from the base  
class?
http://code.google.com/p/gambas/issues/detail?id=78

1) Describe the problem.
The first time the interpreter runs an instruction, it checks what value  
types of the operand(s) are, and saves that. That can be a problem if the  
value types are not the same the next time the code runs.
For example, every time the + operator in the code runs, it saves what  
value types the operands were at the first time, and assumes they are the  
same next time.
That will produce false results if the value types are not the same the  
next time.

2) GIVE THE FOLLOWING INFORMATIONS (if they are appropriate):

Version: TRUNK
Revision: r4007
Operating system: Linux
Distribution: Gentoo
Architecture: x86_64

3) Provide a little project that reproduces the bug or the crash.
Class1:
Public Function F() As Integer
   Return 1
End

Class2: (Derived from Class1)
Inherits Class1
Public Function F() As String
   Return "2"
End

Code:
Dim a As Class1
Dim i As Integer
For i = 1 To 2
   If i = 1 Then
     a = New Class1
   Else If i = 2 Then
     a = New Class2
   End If
   Print a.F() + i 'Will print the address in memory for "2" + i the second  
time
Next

5) Explain clearly how to reproduce the bug or the crash.
Compile (will currently not warn at all) and run the code example.

As far as I know, there are three ways fixing this bug:
1. Remove the optimization.
2. Somehow convert the return value to a Variant if it recognises that it  
may be several return value types.
3. Do not allow an instruction to return different return types, like when  
overriding methods with a different return type.





More information about the User mailing list