Created
December 11, 2018 11:00
-
-
Save sogaiu/901e696a85c6440629b5241f82e54121 to your computer and use it in GitHub Desktop.
attempt 2 at porting clj-1279-3.patch to clr (cf. https://dev.clojure.org/jira/browse/CLJ-1279)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/Clojure/Clojure.Tests/clojure/test_clojure/errors.clj b/Clojure/Clojure.Tests/clojure/test_clojure/errors.clj | |
index 0ae6dfb1..8e1493de 100644 | |
--- a/Clojure/Clojure.Tests/clojure/test_clojure/errors.clj | |
+++ b/Clojure/Clojure.Tests/clojure/test_clojure/errors.clj | |
@@ -23,6 +23,8 @@ | |
(defmacro m1 [a] `(inc ~a)) | |
+(defmacro m2 [] (assoc)) | |
+ | |
(deftest arity-exception | |
;; IllegalArgumentException is pre-1.3 | |
(is (thrown-with-msg? ArgumentException #"Wrong number of args \(1\) passed to" ;;; IllegalArgumentException | |
@@ -35,7 +37,17 @@ | |
(macroexpand `(m1 1 2)))) | |
(is (thrown-with-msg? ArityException (System.Text.RegularExpressions.Regex. (System.Text.RegularExpressions.Regex/Escape "f2:+> | |
<->!#%&*b")) ;;; We don't have \Q... \E : #"\Q/f2:+><->!#%&*|b\E" | |
(f2:+><->!#%&*b 1 2)) | |
;;; f2:+><->!#%&*|b | |
- "ArityException messages should demunge function names")) | |
+ "ArityException messages should demunge function names") | |
+ (is (try | |
+ (macroexpand `(m2)) | |
+ (throw (RuntimeException. "fail")) | |
+ (catch ArityException e | |
+ (is (= 0 (.-actual e)))))) | |
+ (is (try | |
+ (macroexpand `(m2 5)) | |
+ (throw (RuntimeException. "fail")) | |
+ (catch ArityException e | |
+ (is (= 1 (.-actual e))))))) | |
(deftest assert-arg-messages | |
; used to ensure that error messages properly use local names for macros | |
diff --git a/Clojure/Clojure/CljCompiler/Compiler.cs b/Clojure/Clojure/CljCompiler/Compiler.cs | |
index 39bbece4..e783e1b4 100644 | |
--- a/Clojure/Clojure/CljCompiler/Compiler.cs | |
+++ b/Clojure/Clojure/CljCompiler/Compiler.cs | |
@@ -1224,7 +1224,11 @@ namespace clojure.lang | |
catch (ArityException e) | |
{ | |
// hide the 2 extra params for a macro | |
- throw new ArityException(e.Actual - 2, e.Name); | |
+ if (e.Name.Equals(munge(v.ns.Name.Name) + "$" + munge(v.sym.Name))) { | |
+ throw new ArityException(e.Actual - 2, e.Name); | |
+ } else { | |
+ throw e; | |
+ } | |
} | |
} | |
else | |
diff --git a/Clojure/Clojure/Lib/AFn.cs b/Clojure/Clojure/Lib/AFn.cs | |
index d60d86e6..91d2bdf5 100644 | |
--- a/Clojure/Clojure/Lib/AFn.cs | |
+++ b/Clojure/Clojure/Lib/AFn.cs | |
@@ -467,7 +467,7 @@ namespace clojure.lang | |
string name = this is Var.Unbound ? (this as Var.Unbound).ToString() : Util.NameForType(GetType()); | |
return new ArityException( | |
reqArity, | |
- Compiler.demunge(name)); | |
+ name); | |
} | |
#endregion | |
diff --git a/Clojure/Clojure/Lib/ArityException.cs b/Clojure/Clojure/Lib/ArityException.cs | |
index b2d67bbd..d17193c0 100644 | |
--- a/Clojure/Clojure/Lib/ArityException.cs | |
+++ b/Clojure/Clojure/Lib/ArityException.cs | |
@@ -46,7 +46,7 @@ namespace clojure.lang | |
} | |
public ArityException(int actual, string name, Exception cause) | |
- : base("Wrong number of args (" + actual + ") passed to: " + name, cause) | |
+ : base("Wrong number of args (" + actual + ") passed to: " + Compiler.demunge(name), cause) | |
{ | |
_actual = actual; | |
_name = name; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment