Opened 6 years ago

Closed 4 months ago

#1481 closed defect (fixed)

compiler type warning (but no need for a warning)

Reported by: snoewchen Owned by:
Priority: minor Milestone: someday
Component: compiler Version: 4.13.0
Keywords: compiler warning Cc:
Estimated difficulty:

Description

In the attached file there are 3 versions of a procedure "assq-val" that returns the associated value to a given key.

The procedure distinguishes if "assq" found really just a pair or a list, so that

  (assq-val 'a '((a . "b"))) => "b" ; obviously
  (assq-val 'a '((a "b)) => "b" ; instead of '("b")

You can find 3 Variants in the file (all 3 variants should be semantically equal):

a) assq-val-no-warning
b) assq-val-warning
c) assq-val-also-no-warning

The strange thing is that the compiler says (for version (b) "assq-val-warning")

Warning: in toplevel procedure `assq-val-warning':
  (...:21) in procedure call to `cdr', expected argument #1 
  of type `pair' but was given an argument of type `false'

The call "(cdr el)" is in the if-branch of "(if (pair? el)" - so no risk for "el" to be #f.

What's even more perplexing - version (c) of "assq-val" is the same as version (b) - just the "let"-form of version (b) is replaced by a "define" - and with that change the compiler warning goes away.

(I discovered the warning the other way around actually - beeing a scheme rookie the first version had the "define" form (more beginner friendly because less parens) - after some days of hacking I replaced the "define"-form with let - and boom - compiler warning.)

My chicken version:

(c) 2008-2017, The CHICKEN Team
(c) 2000-2007, Felix L. Winkelmann
Version 4.13.0 (rev 68eeaaef)
linux-unix-gnu-x86-64 [ 64bit manyargs dload ptables ]
compiled 2017-12-11 on yves.more-magic.net (Linux)

Attachments (1)

compiler-warning.scm (1.1 KB) - added by snoewchen 6 years ago.
"assq-val-warning" produces the compiler warning

Download all attachments as: .zip

Change History (3)

Changed 6 years ago by snoewchen

Attachment: compiler-warning.scm added

"assq-val-warning" produces the compiler warning

comment:1 Changed 6 years ago by snoewchen

This bug seems to be resolved in chicken 5

Tested with: chicken -version

CHICKEN
[...]
Version 5.0.0 (rev 317dbeaa) <== 2018-06-28 09:00:23
linux-unix-gnu-x86-64 [ 64bit dload ptables ]

comment:2 Changed 4 months ago by felix winkelmann

Resolution: fixed
Status: newclosed
Note: See TracTickets for help on using tickets.