rsdn/nemerle — Issue #223: NullReferenceException when changing field for instance of immutable type
Author: russianfacepalm
Created: 2012-01-01 18:42:47+00:00
State: open

I've found that when you're changing field of immutable type, you'll get NullReferenceException at runtime. It's so confusing, and looks like it's a bug.

I am having this bug in following example.
On a C#'s side I have this struct:

```c#
struct Vector3
{
public float X;
public float Y;
public float Z;

[...]
}
```
Then, I am declaring instance of this struct inside my Nemerle program:

```nemerle
def vec3 = Vector3();
```

After that, when I am changing value like this:

```nemerle
vec3.X += 10;
```

Program fails with **NullReferenceException** at runtime.

This exception is caused by instance of Vector3. Only because its immutable.
If I change it to mutable:

```nemerle
mutable vec3 = Vector3();
vec3.X += 10;
```
No exception will be thrown.