Forums

possibly incorrect error message

General discussion about Cobra. Releases and general news will also be posted here.
Feel free to ask questions or just say "Hello".

possibly incorrect error message

Postby kobi7 » Tue Dec 17, 2013 4:26 am

Code: Select all
Garden.cobra(0,0): Warning: The expression "plant" (of type "IFieldItem") will always evaluate to true because it is not nilable. You can remove the expression.


the expression is:
Code: Select all
if plant


an empty spot in the field is the nil value.
there is a list (actually now multilist) of IFieldItem which is an interface, and not initialized.
I think the warning is wrong.
just a report
kobi
Falun Dafa is Good.
Truth, Compassion, Forbearance is Good.
kobi7
 
Posts: 82
Location: Israel

Re: possibly incorrect error message

Postby kobi7 » Tue Dec 17, 2013 4:27 am

the whole method:
Code: Select all
def print
      print "FIELD:"
      for y in .width to int
         for x in .length to int
            plant = .field[x,y]
            if plant
               ch = plant.asChar
               print ch stop
            else
               print c'+' stop
         print
Falun Dafa is Good.
Truth, Compassion, Forbearance is Good.
kobi7
 
Posts: 82
Location: Israel

Re: possibly incorrect error message

Postby kobi7 » Tue Dec 17, 2013 4:50 am

my understanding is that since an array cannot instantiate an interface, the cells will have nil values instead (this is a multilist)

the problem also shows as an error:
Code: Select all
   def canPlaceObject(x as int, y as int) as bool
       """the basic rule is the position is vacant/empty"""
      return .field[x,y] is nil


Code: Select all
Error: The left and right sides of the "is" expression can never be identical because of their types ("IFieldItem" and "nil").


I can use a singleton instead, ofcourse, but i think this is a valid usage.
should I just change to "IFieldItem?" everywhere?
Falun Dafa is Good.
Truth, Compassion, Forbearance is Good.
kobi7
 
Posts: 82
Location: Israel

Re: possibly incorrect error message

Postby kobi7 » Tue Dec 17, 2013 4:55 am

okay, I decided it would be more correct to indeed use the nullable "IFieldItem?".
however the first warning would still be wrong for an array of interfaces, as the value inside is indeed nil.
Falun Dafa is Good.
Truth, Compassion, Forbearance is Good.
kobi7
 
Posts: 82
Location: Israel

Re: possibly incorrect error message

Postby Charles » Tue Dec 17, 2013 5:55 am

kobi7 wrote:okay, I decided it would be more correct to indeed use the nullable "IFieldItem?".
however the first warning would still be wrong for an array of interfaces, as the value inside is indeed nil.

Perhaps we should say that allowing an array of IFoo is what's wrong and that it has to be an array of IFoo? since it will indeed start with nil. Make sense?

In the future, please include more relevant portions of the source. For example, if Cobra is complaining that the usage of a var, then including the declaration of the var would be informative. The best is always a self contained, small, complete program. But when that's not possible, including all the relevant pieces makes sense.
Charles
 
Posts: 2510
Location: Los Angeles, CA

Re: possibly incorrect error message

Postby kobi7 » Fri Dec 27, 2013 12:20 am

yea, makes sense.
Please accept my apology, I didn't mean to blame anyone. just had too much coffee, lost focus, and was frustrated with slow progress
Falun Dafa is Good.
Truth, Compassion, Forbearance is Good.
kobi7
 
Posts: 82
Location: Israel

Re: possibly incorrect error message

Postby Charles » Fri Dec 27, 2013 1:17 pm

No worries.
Charles
 
Posts: 2510
Location: Los Angeles, CA


Return to Discussion

Who is online

Users browsing this forum: No registered users and 3 guests

cron