Possible Bug in Reflection

Archives Forums/BlitzMax Bug Reports/Possible Bug in Reflection

Macguffin(Posted 2009) [#1]
I'm using reflection to null all the fields within a type. When this leads to setting a primitive type to null, I get a null reference crash. Since in the Help files it describes Null as returning a zero, null object, etc. depending on context, I thought this might be a bug. Bug repro here:

SuperStrict

Type TFoo
	Field theInt:Int

	Method ResetFields()
		Local selfID:TTypeId = TTypeId.ForObject(Self)
		Local fieldList:TList = selfID.EnumFields()
		For Local theField:TField = EachIn fieldList
		  theField.Set(Self, Null)
		Next
	End Method
End Type

Local foo:TFoo = New TFoo
foo.theInt = 10
foo.ResetFields()


The workaround I'm using is to do a Select/Case set for all the primitives. I tried doing this with an if statement using logical OR to string together the primitive types - that led to things bombing out on some of the more complex object types. That may be a second bug, but I don't have time to look into it further right now. Apologies.

My system is a Dell Vostro 1500 running XP. Core2 Duo 1.4ghz. 2 gig ram, Intel 965 integrated graphics.

Thanks,

Scott


_Skully(Posted 2009) [#2]
Null is aways object oriented and is very different than a 0

Try setting an int to null...bark!


Macguffin(Posted 2009) [#3]
I figured that was the case, but since the help topic for Expressions says this, I figured I'd ask:

"Null returns 0, an empty string, an empty array, the null object or a pointer to 0 depending on context. "


N(Posted 2009) [#4]
I can only guess that the first one applies only to non-Strict builds where objects are automatically converted to integer handles and such.


Macguffin(Posted 2009) [#5]
That'd make sense. Thanks.


Otus(Posted 2009) [#6]
Aren't primitive fields set using a string representation? It's not exactly a bug maybe, but I think using value.ToString().ToInt() instead of Int(String(value)) in the reflection module does not make much sense.

Using i:Int = Null in normal code works just fine. Regardless of strictness.


Macguffin(Posted 2009) [#7]
We are sadly now far past my understandings of the inner workings of BlitzMax. ;D