#2256 Improve Map.make error message

SlimerDude Wed 9 Apr 2014

Hi, can someone explain the following to me:

class Example {
  Void main() {
    echo(Int#  .fits(Int?#  ))  // --> true
    echo(Int[]#.fits(Int[]?#))  // --> false
  }
}

Non-nullable Int fits into nullable Int? - that's fine, I understand because:

Int? int := 42      // is okay

But when I turn both types into a List, why does the same not hold true?

I can still do:

Int[]? list := [42] // is also okay

so why does Int[]#.fits(Int[]?#) return false?

In a new library, I'm dynamically setting fields and making sanity checks (using fits()) and this quirk is giving me trouble!

brian Wed 9 Apr 2014

I think that just might be an oversight - the whole fits thing with nullability is a bit quirky since its a layer we add above the JVM. I can look at fixing - but will be a week or two, or if you want to email a patch I can work with you.

In the meantime, I will often make all my type checks against Type.toNonNullable to remove nullability from the equation

SlimerDude Wed 9 Apr 2014

Hi, I did end up using Type.toNonNullable() and doing a manual null check if required.

While we're on the topic, I also noticed that:

mapType := Map?#
map := Map(mapType)

causes:

sys::CastErr: java.lang.ClassCastException: 
  fan.sys.NullableType cannot be cast to fan.sys.MapType
  fan.sys.Map.make (Map.java:35)
  ....

Is that part of the same quirk?

I was manually creating parameterized Maps...

mapType = mapType.parameterize(["K":keyType, "V":valType])

I can work with them for now, but it'd be nice if they were ticket'ed and made it into the next Fantom release. :D

(I may even look at a patch!)

Cheers,

Steve.

brian Wed 9 Apr 2014

Promoted to ticket #2256 and assigned to brian

s that part of the same quirk?

That is really something different. The Map constructor must take a Map type. Maybe ClassCastException isn't the best way to report that - but essentially its just an argument error problem.

But I'll track this a ticket - definitely agree we need a little cleanup to make things consistent

brian Thu 8 Jan 2015

Rename from "List types and nullability"

brian Thu 8 Jan 2015

Ticket resolved in 1.0.67

Fixed up Map.make(Type) to report more meaningful error message when not passed a non-nullable map type

Login or Signup to reply.