Clojure

The compiler ignores too few or too many arguments to throw

Details

  • Type: Enhancement Enhancement
  • Status: Open Open
  • Priority: Major Major
  • Resolution: Unresolved
  • Affects Version/s: Release 1.6
  • Fix Version/s: None
  • Component/s: None
  • Labels:
  • Patch:
    Code and Test
  • Approval:
    Triaged

Description

The compiler does not fail on "malformed" throw forms:

user=> (defn foo [] (throw))
#'user/foo

user=> (foo)
NullPointerException   user/foo (NO_SOURCE_FILE:1)

user=> (defn bar [] (throw Exception baz))
#'user/bar

user=> (bar)
ClassCastException java.lang.Class cannot be cast to java.lang.Throwable  user/bar (NO_SOURCE_FILE:1)

; This one works, but ignored-symbol, should probably not be ignored
user=> (defn quux [] (throw (Exception. "Works!") ignored-symbol))
#'user/quux

user=> (quux)
Exception Works!  user/quux (NO_SOURCE_FILE:1)

The compiler can easily avoid these by counting forms.

Activity

Hide
Alf Kristian Støyle added a comment -

Not sure how to create a test for the attached patch. Will happily do so if anyone has a suggestion.

Show
Alf Kristian Støyle added a comment - Not sure how to create a test for the attached patch. Will happily do so if anyone has a suggestion.
Hide
Alex Miller added a comment -

Re testing, I think the examples you give are good - you should add tests to test/clojure/test_clojure/compilation.clj that eval the form and expect compilation errors. I'm sure you can find similar examples.

Show
Alex Miller added a comment - Re testing, I think the examples you give are good - you should add tests to test/clojure/test_clojure/compilation.clj that eval the form and expect compilation errors. I'm sure you can find similar examples.
Hide
Alf Kristian Støyle added a comment -

Newest patch also contains a few tests.

Show
Alf Kristian Støyle added a comment - Newest patch also contains a few tests.

People

Vote (0)
Watch (1)

Dates

  • Created:
    Updated: