TTypeID.ForObject( ).name() returns abstract name
BlitzMax Forums/BlitzMax Programming/TTypeID.ForObject( ).name() returns abstract name
| ||
Hey, I have an error, which I cant really get my head around.. Consider this scenario: Type MyAbstractType Abstract End Type Type MyInheritingType Extends MyAbstractType End Type Local MyObject:MyInheritingType = New MyInheritingType Print "class= "+TTypeID.ForObject( MyObject ).name() This should output "class= MyInheritingType", shouldnt it? [And it does, as Htbaa proved below.] My Problem: I have code of mine returning the name of an abstract type!? How can that happen? Any Ideas? I know you can create objects of abstract types via reflection, but I am sure I dont do. |
| ||
Building untitled1 Compiling:untitled1.bmx flat assembler version 1.68 (1653550 kilobytes memory) 3 passes, 4243 bytes. Linking:untitled1.debug.mt.exe Executing:untitled1.debug.mt.exe class= MyInheritingType Process complete Works fine. What version of Blitzmax are you using? |
| ||
Uh, I use BlitzMax 1.36, normal-threaded built. Of course that code I wrote there works fine, because I just wanted to cut a long story short by writing it. It's not the actual code I use (which is 200 times longer). My question was: What circumstances could lead to the reflection outputting an abstract type's name for an object that is actually of a none-abstract type? |
| ||
Srry, I have no current installation of BMax running, but: Does this maybe happen when you write: Local MyObject:MyAbstractType = New MyInheritingType |
| ||
Are you sure you haven't some how got the super class? |
| ||
Kurator's suggestion is most likely your problem. |
| ||
What Kurator said doesn't happen due to polymorphism. Edit: MyObject points to an instance of MyInheritingType even though its declared as MyAbstractType. |
| ||
What circumstances could lead to the reflection outputting an abstract type's name for an object that is actually of a none-abstract type? Horrible mistakes - including, but not limited to, unintentionally overwriting the clas member of the object, instantiating the abstract member, etc.Edit: It may also be possible that the info stored by the reflection module was somehow modified/corrupted (not the data that the module uses to get the info, just the info itself). |
| ||
Yes, Azathoth is right, there must be another bug in your code, I guess Niliums hints are a good tip to begin searching :) |
| ||
I once encountered something similar. When inheriting from a class and using reflection inside the constructor of a child class it seemed as the type at that point actually was the parent class. If I moved the reflection outside the constructor (after the child-class was instanced) everything was alright and the TTypeInfo was correct for the child class. I didn't investigate further back then, but I just wanted to mention this as this might be the same or a very similar problem. |
| ||
Using reflection in a constructor is also a bad idea. Does the instance you're creating have code in the constructor of its abstract superclass to get the TTypeID of itself? |