opendylan icon indicating copy to clipboard operation
opendylan copied to clipboard

Confusing warning for many return values

Open cgay opened this issue 6 years ago • 5 comments

/home/cgay/dylan/ws.all/time/time.dylan:58-65: Warning - 
Result type check can fail - values(singleton(0 :: <integer>), singleton(0 :: <integer>),
 singleton(0 :: <integer>), singleton(0 :: <integer>), singleton(0 :: <integer>),
 singleton(0 :: <integer>), singleton(0 :: <integer>), <object>) inferred,
 values(<abstract-integer>, <month>, <abstract-integer>, <abstract-integer>,
 <abstract-integer>, <abstract-integer>, <abstract-integer>, <zone>) expected.
      -------------------------
  58  define method decode-time
  59      (t :: <time>)
  60   => (year :: <integer>, month :: <month>, day :: <integer>,
      [...]
  64    values(0, 0, 0, 0, 0, 0, 0, $utc)
  65  end;
      ---

Perhaps, when there are many return values, it would be useful to say how many were expected and how many were returned.

(Separate issue, but I'll drop it here for now... All of those singleton(0 :: <integer>)s would sure be easier to read as 0. This doesn't strike me as counter-intuitive for types that have built-in literal syntax.)

cgay avatar Jan 30 '19 03:01 cgay

Also, judicious use of \n would make this a lot easier to read. For example,

Warning - Result type check can fail:
8 values expected: ...
8 values inferred: ...

cgay avatar Jan 30 '19 14:01 cgay

Better yet:

Warning - Result type check can fail:
     Return value "year" - expected: type1, actual: type1
 ->  Return value "month" - expected: type2, actual: type3
     Return value "_" - expected: type4, actual: type4

The leading -> indicates where there's a type mismatch.

If for some reason the names of the return values aren't available easily a 1-based index can be used.

cgay avatar Jan 30 '19 19:01 cgay

For the original error posted above, we would have...

/home/cgay/dylan/ws.all/time/time.dylan:58-65: Warning - Result type check can fail:
     Return value "year" - expected: <abstract-integer>, actual: singleton(0 :: <integer>)
  -> Return value "month" - expected <month>, actual: singleton(0 :: <integer>)
     Return value "day" - expected: <abstract-integer>, actual: singleton(0 :: <integer>)
     Return value "hour" - expected: <abstract-integer>, actual: singleton(0 :: <integer>)
     Return value "minute" - expected: <abstract-integer>, actual: singleton(0 :: <integer>)
     Return value "second" - expected: <abstract-integer>, actual: singleton(0 :: <integer>)
     Return value "nanosecond" - expected: <abstract-integer>, actual: singleton(0 :: <integer>)
  -> Return value "zone" - expected: <zone>, actual: <object>
      -------------------------
  58  define method decode-time
  59      (t :: <time>)
  60   => (year :: <integer>, month :: <month>, day :: <integer>,
      [...]
  64    values(0, 0, 0, 0, 0, 0, 0, $utc)
  65  end;
      ---

cgay avatar Jan 30 '19 19:01 cgay

I wouldn't be surprised if warnings for callers not matching function args needs similar treatment.

cgay avatar Jan 30 '19 19:01 cgay

This TODO covers part of what I reported above. https://github.com/dylan-lang/opendylan/blob/master/sources/dfmc/optimization/constant-folding.dylan#L708

cgay avatar Feb 02 '19 22:02 cgay