Summary
compiler type warning (but no need for a warning)
Metadata
- Id: 4fa2129f07158e52ae355bd4f55c945175b3a945
- Trac id: 1481
- Type: defect
- Reporter: snoewchen
- Owner:
- Cc:
- Status: closed
- Component: compiler
- Estimated difficulty:
- Resolution: fixed
- Priority: minor
- Milestone: someday
- Version: 4.13.0
- Changetime: 2023-11-06 23:37:20 UTC
- Created: 2018-07-01 01:05:10 UTC
- Keywords: compiler warning
Attachments
- 4fa2129f07158e52ae355bd4f55c945175b3a945/attachments/compiler-warning.scm
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)
Changes and comments
[2018-07-01 01:06:07 UTC] snoewchen attached compiler-warning.scm (description="assq-val-warning" produces the compiler warning)
[2018-07-02 16:11:03 UTC] snoewchen wrote:
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 ]]