From e9c57befd3d6ba98b280eecf021b70a7484c306d Mon Sep 17 00:00:00 2001 From: Vincenzo Palazzo Date: Thu, 7 Apr 2022 00:19:20 +0200 Subject: [PATCH] compilation: introduce a known error regarding the references mismatch Signed-off-by: Vincenzo Palazzo --- .../known_errors/testdata/c_err_with_def.vv | 61 +++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 vlib/v/tests/known_errors/testdata/c_err_with_def.vv diff --git a/vlib/v/tests/known_errors/testdata/c_err_with_def.vv b/vlib/v/tests/known_errors/testdata/c_err_with_def.vv new file mode 100644 index 0000000000..5a731c45ae --- /dev/null +++ b/vlib/v/tests/known_errors/testdata/c_err_with_def.vv @@ -0,0 +1,61 @@ +import math + +struct Vector{ + x f64 + y f64 +} + +struct Vector3d{ + x f64 + y f64 + z f64 +} + +struct Position{ + x f64 + y f64 +} + +struct Position3d{ + x f64 + y f64 + z f64 +} + +fn new_position (v &Vector, p &Position, time f32) Vector{ + x := v.x*time + y := v.y*time + return Vector{p.x + x, p.y + y} +} + +fn acceleration(u &Vector, v &Vector, time f32) Vector{ + x := u.x+v.x/time + y := u.y+u.y/time + return Vector{x, y} +} + +fn magnitude3d(v3d &Vector3d) f64{ + return math.sqrt(math.pow(v3d.x,2)+math.pow(v3d.y,2)+math.pow(v3d.z,2)) +} + +fn magnitude(v &Vector) f64{ + return math.sqrt(math.pow(v.x, 2)+math.pow(v.y, 2)) + +} + +fn unit_vector(v &Vector) Vector{ + x := v.x/magnitude(v) + y := v.y/magnitude(v) + return Vector{x, y} +} + +fn unit_vector3d(v &Vector3d) Vector3d{ + x := v.x/magnitude3d(v) + y := v.y/magnitude3d(v) + z := v.z/magnitude3d(v) + return Vector3d{x, y, z} +} + +mut object := Vector{4,3} + +println(acceleration(Vector{0,0}, object, 5))