bad-voidexp.scm 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. (define-variable pp #f)
  2. ;; Missing else.
  3. (format #t "loop1: ~s~%"
  4. (let loop1 ((n 1))
  5. (cond
  6. ((= n 0) #t)
  7. ((and n (if pp #f)) (loop1 (- n 1))))))
  8. ;; Diagnostic: bad-voidexp.scm:7:20: warning - missing else where value is required
  9. ;; Output: loop1: #t
  10. ;; Missing else, condition false
  11. (format #t "loop2: ~s~%"
  12. (let loop2 ((n 1))
  13. (cond
  14. ((= n 0) #t)
  15. ((and n (if #f #f)) (loop2 (- n 1))))))
  16. ;; Diagnostic: bad-voidexp.scm:16:20: warning - missing else where value is required
  17. ;; Output: loop2: #t
  18. ;; Missing else, condition true
  19. (format #t "loop3: ~s~%"
  20. (let loop3 ((n 1))
  21. (cond
  22. ((= n 0) #t)
  23. ((and n (if #t #f)) (loop3 (- n 1))))))
  24. ;; Output: loop3: #!void
  25. ;; void expression in define lhs
  26. (define val4 ((lambda () (sleep 0.015))))
  27. ;; Diagnostic: bad-voidexp.scm:29:26: warning - void-valued expression where value is needed
  28. (set! val4 (if (not pp) 5))
  29. ;; Diagnostic: bad-voidexp.scm:32:12: warning - missing else where value is required
  30. (format #t "val4 #1: ~w~%" val4)
  31. ;; Output: val4 #1: 5
  32. (set! val4 (if (sleep 0.015) 11 12))
  33. (format #t "val4 #2: ~w~%" val4)
  34. ;; Diagnostic: bad-voidexp.scm:37:12: warning - void-valued condition is always true
  35. ;; Output: val4 #2: 11
  36. (set! val4 (car (cons 13 (sleep 0.013))))
  37. (format #t "val4 #3: ~w~%" val4)
  38. ;; Output: val4 #3: 13
  39. ;; No diagnostic if void-expression explicitly cast to object.
  40. (set! val4 (car (cons 14 (->object (sleep 0.014)))))
  41. (format #t "val4 #4: ~w~%" val4)
  42. ;; Output: val4 #4: 14
  43. ;; Based on Savannah bug#18736, "intenal compile error -- svn rev 5816".
  44. ;; From Thomas Kirk <tk@research.att.com>
  45. (format #t "test-savannah-18736: ~w~%"
  46. (let* ((elapsed 0)
  47. (oldtime (java.lang.System:currentTimeMillis))
  48. (val ((lambda () (sleep 0.015))))
  49. (ignored
  50. (begin
  51. (set! elapsed
  52. (- (java.lang.System:currentTimeMillis) oldtime))
  53. val)))
  54. ;; While time resolution is non-portable, assume a sleep of 20ms
  55. ;; will be detectable as taking at least 10ms.
  56. (>= elapsed 10)))
  57. ;; Diagnostic: bad-voidexp.scm:56:33: warning - void-valued expression where value is needed
  58. ;; Output: test-savannah-18736: #t
  59. (format #t "compare 3 2: ~s~%"
  60. (cond ((> (car (list 3)) 2) 'greater)
  61. ((< (car (list 3)) 2) 'less)))
  62. ;; Diagnostic: bad-voidexp.scm:69:9: warning - missing else where value is required
  63. ;; Output: compare 3 2: greater
  64. (let ()
  65. (define (bar) :: void
  66. (let ((y (display "foo")))
  67. y))
  68. (let ((x (bar)))
  69. x)
  70. (newline))
  71. ;; Diagnostic: bad-voidexp.scm:76:14: warning - void-valued expression where value is needed
  72. ;; Diagnostic: bad-voidexp.scm:78:12: warning - void-valued expression where value is needed
  73. ;; Output: foo
  74. ;; Savannah bug #27014 "AND vs. VOID"
  75. (begin
  76. (define (foo) (and (bar) (bar)))
  77. (define baz #f)
  78. (define (bar) (set! baz #f)))
  79. ;; Diagnostic: bad-voidexp.scm:87:22: warning - void-valued expression where value is needed