#1449 Comparisons to null in constructors

brian Thu 17 Mar 2011

This was discussed a couple of weeks ago, and I've run into it a couple times now. Sometimes in an it-block constructor you want to check if a field has been assigned yet to determine if you should do a default assignment. For example:

new make(|This| f)
{
  f(this)
  if (dir != null) dir = ...
}

const File dir

Since we don't allow you compare non-nullable field to null this was sort of awkward. What I decided to do is to disable non-nullable comparison errors if:

  1. inside an it-block constructor
  2. the comparison is on a field of this

changeset

Login or Signup to reply.