Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

by-ref broken #114

Open
timsgardner opened this issue Jan 30, 2015 · 1 comment
Open

by-ref broken #114

timsgardner opened this issue Jan 30, 2015 · 1 comment
Labels
bug clojure-clr notable-bug Bugs worth making special note of in the docs solved in magic

Comments

@timsgardner
Copy link
Contributor

by-ref parameters are broken. I suspect this has to do with the increasingly unacceptable absence of primitive locals.

Given the following file:

(ns by-ref.angle-axis
  (:use arcadia.core)
  (:import [UnityEngine Vector3 Quaternion]))

(defn v3 ^Vector3 [x y z]
  (Vector3. x y z))

(defn angle-axis-1 [^Quaternion q]
  (let [ang (float 0)
        axis Vector3/zero]
    (.ToAngleAxis q (by-ref ang) (by-ref axis))
    [ang axis]))

(defn angle-axis-2 [^Quaternion q]
  (let [ang (float 0)
        axis (v3 1 2 3)]
    (.ToAngleAxis q (by-ref ang) (by-ref axis))
    [ang axis]))

we get the following behavior:

by-ref.angle-axis=> (angle-axis-1 (Quaternion/Euler (v3 10 10 10)))
[16.78646 (0.6, 0.5, 0.5)]

by-ref.angle-axis=> (angle-axis-2 (Quaternion/Euler (v3 10 10 10)))
System.NullReferenceException: Object reference not set to an instance of an object
  at (wrapper stelemref) object:stelemref (object,intptr,object)
  at by_ref/angle_axis$angle_axis_2__30.invoke (System.Object ) [0x00000] in <filename unknown>:0 
  at by_ref/angle_axis$eval__71__76.invoke () [0x00000] in <filename unknown>:0 
  at clojure.lang.Compiler.eval (System.Object form) [0x00000] in <filename unknown>:0 
  at clojure.lang.Compiler.eval (System.Object form) [0x00000] in <filename unknown>:0 
  at clojure/core$eval__49976.invoke (System.Object ) [0x00000] in <filename unknown>:0 
  at arcadia/repl$repl_eval_print$fn__892__896.invoke () [0x00000] in <filename unknown>:0 
  at arcadia/repl$repl_eval_print__899.invoke (System.Object , System.Object ) [0x00000] in <filename unknown>:0 
  at arcadia/repl$repl_eval_string__915.invoke (System.Object , System.Object ) [0x00000] in <filename unknown>:0 
  at arcadia/repl$repl_eval_string__915.invoke (System.Object ) [0x00000] in <filename unknown>:0 
  at arcadia/repl$eval_queue$fn__923__927.invoke () [0x00000] in <filename unknown>:0 

The only substantive difference in the IL of the two functions is the type-hinting on axis.
For angle-axis-1:

...
public override object invoke (object obj)
{
    float num = RT.floatCast (0L);
    Vector3 zero = Vector3.zero;
    ((Quaternion)obj).ToAngleAxis (out num, out zero);
    return RT.vector (new object[]
    {
        num,
        zero
    });
}
...

axis corresponding to zero here.
For angle-axis-2:

...
public override object invoke (object obj)
{
    float num = RT.floatCast (0L);
    object obj2 = ((IFn)by_ref/angle_axis$angle_axis_2__30.const__2.getRawRoot ()).invoke (by_ref/angle_axis$angle_axis_2__30.const__3, by_ref/angle_axis$angle_axis_2__30.const__4, by_ref/angle_axis$angle_axis_2__30.const__5);
    ((Quaternion)obj).ToAngleAxis (out num, out obj2);
    return RT.vector (new object[]
    {
        num,
        obj2
    });
}
...

axis corresponding to obj2. It looks like the by-ref form fails because the type of obj2 remains object, and no corrective cast is made.

@timsgardner
Copy link
Contributor Author

To say nothing of gratuitous weirdnesses like float num = RT.floatCast (0L);

nasser added a commit that referenced this issue Sep 27, 2017
It cannot compile correctly due to a compiler bug related
to #114
nasser added a commit that referenced this issue Dec 10, 2017
Avoids a compiler bug documented in #114. Fixes #267.
@timsgardner timsgardner added notable-bug Bugs worth making special note of in the docs solved in magic labels Oct 1, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug clojure-clr notable-bug Bugs worth making special note of in the docs solved in magic
Projects
None yet
Development

No branches or pull requests

1 participant