From b9e9664c33f362453bd46c73774bff9b776a45cb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ingo=20Pr=C3=B6tel?= Date: Sat, 24 Feb 2024 15:01:16 +0100 Subject: [PATCH] Fixed some failing tests. --- include/cpp2util.h | 1 + regression-tests/mixed-type-safety-1.cpp2 | 2 +- regression-tests/pure2-last-use.cpp2 | 162 +++++++++++----------- 3 files changed, 83 insertions(+), 82 deletions(-) diff --git a/include/cpp2util.h b/include/cpp2util.h index c5f648ead..678a8a449 100644 --- a/include/cpp2util.h +++ b/include/cpp2util.h @@ -696,6 +696,7 @@ class owning_reference { owning_reference& operator=(owning_reference&& ref) noexcept = default; typename std::add_lvalue_reference::type operator*() const { return *assert_not_null(_ptr.get()); } typename std::add_lvalue_reference::type operator->() const noexcept {return *assert_not_null(_ptr.get());} + auto get() const noexcept { return _ptr.get();} private: std::unique_ptr _ptr; }; diff --git a/regression-tests/mixed-type-safety-1.cpp2 b/regression-tests/mixed-type-safety-1.cpp2 index d7fb8adf9..1fc22dfa3 100644 --- a/regression-tests/mixed-type-safety-1.cpp2 +++ b/regression-tests/mixed-type-safety-1.cpp2 @@ -29,7 +29,7 @@ main: () -> int = print( "1 is int? ", 1 is int ); c := new(); // safe by construction - s : * Shape = c.get(); // safe by Lifetime + s : * Shape = c*.get(); // safe by Lifetime print("\ns* is Shape? ", s* is Shape ); print( "s* is Circle? ", s* is Circle ); print( "s* is Square? ", s* is Square ); diff --git a/regression-tests/pure2-last-use.cpp2 b/regression-tests/pure2-last-use.cpp2 index d924b777d..abf1b8ae1 100644 --- a/regression-tests/pure2-last-use.cpp2 +++ b/regression-tests/pure2-last-use.cpp2 @@ -7,57 +7,57 @@ identity_copy: (copy x) x; issue_313: () = { _ = :() -> std::vector = { - a := new(0); + a := new(0)*; return (a*, identity_copy(a)*); }; _ = :() -> std::vector = { - a := new(0); + a := new(0)*; return (a&**, identity_copy(a)*); }; _ = :() -> int = { - a := new(0); + a := new(0)*; return identity(a)* + identity(a)*; - b := new(0); + b := new(0)*; return identity(b)* = identity(b)*; - c := new(0); + c := new(0)*; return identity(c)* ^ identity(c)*; }; { - a := new(0); + a := new(0)*; identity(a)* = identity(a)*; - b := new(0); + b := new(0)*; _: int = identity(b)* = identity(b)*; - c := new(0); + c := new(0)*; if identity(c)* * identity(c)* { } - d := new(0); + d := new(0)*; if (identity(d)* - identity(d)*) { } - e := new(0); + e := new(0)*; _ = e is (e); - f := new(0); + f := new(0)*; _ = f is std::type_identity_t; // OK? - g := new(0); + g := new(0)*; for (identity(g)* + identity(g)*) do (_) { } - h := new(0); + h := new(0)*; while identity(h)* + identity(h)* { } - i := new(0); + i := new(0)*; do { } while identity(i)* + identity(i)*; - j := new(0); - k := new(0); + j := new(0)*; + k := new(0)*; _ = inspect identity(j)* + identity(j)* -> int { is (identity(k)* + identity(k)*) = 0; is _ = 0; @@ -65,7 +65,7 @@ issue_313: () = { } { - a := new(0); + a := new(0)*; _ = :() identity(a$)* + identity(a$)*; } } @@ -113,7 +113,7 @@ issue_683: (args) = { issue_825: () = { _ = :(copy b: std::unique_ptr) f_copy(b); _ = :(move c: std::unique_ptr) f_copy(c); - _ = :(forward d) f_copy(d);(new(0)); + _ = :(forward d) f_copy(d);(new(0)*); } issue_832: () = { @@ -369,16 +369,16 @@ issue_857_9: @struct type = { } issue_869_0: @value type = { - operator=: (out this, move _: std::unique_ptr) = { } + operator=: (out this, move _: cpp2::owning_reference) = { } } issue_869_1: @union type = { i: issue_869_0; } -issue_869_2: () -> (res: issue_869_1 = ()) = { res.set_i(new(0)); } +issue_869_2: () -> (res: issue_869_1 = ()) = { res.set_i(new(0)*); } issue_884: () = { _ = :() = { - x := new(0); + x := new(0)*; if true { } { { f_inout(x); } @@ -387,7 +387,7 @@ issue_884: () = { }; _ = :() = { - x := new(0); + x := new(0)*; if true { f_copy(x); } @@ -398,7 +398,7 @@ issue_884: () = { }; _ = :() = { - x := new(0); + x := new(0)*; if true { f_inout(x); } @@ -410,7 +410,7 @@ issue_884: () = { }; _ = :() = { - x := new(0); + x := new(0)*; f_copy(x); if true { _ = 0; @@ -423,7 +423,7 @@ issue_884: () = { }; _ = :() = { - x := new(0); + x := new(0)*; f_inout(x); if true { f_copy(x); @@ -436,7 +436,7 @@ issue_884: () = { }; _ = :() = { - x := new(0); + x := new(0)*; f_inout(x); if true { _ = 0; @@ -449,7 +449,7 @@ issue_884: () = { }; _ = :() = { - x := new(0); + x := new(0)*; f_inout(x); if true { _ = 0; @@ -462,7 +462,7 @@ issue_884: () = { }; _ = :() = { - x := new(0); + x := new(0)*; f_inout(x); if true { _ = 0; @@ -475,7 +475,7 @@ issue_884: () = { }; _ = :() = { - x := new(0); + x := new(0)*; f_inout(x); if true { f_copy(x); @@ -488,7 +488,7 @@ issue_884: () = { }; _ = :() = { - x := new(0); + x := new(0)*; f_inout(x); if true { f_copy(x); @@ -501,7 +501,7 @@ issue_884: () = { }; _ = :() = { - x := new(0); + x := new(0)*; f_inout(x); if true { f_inout(x); @@ -517,7 +517,7 @@ issue_884: () = { }; _ = :() = { - x := new(0); + x := new(0)*; f_inout(x); if true { f_inout(x); @@ -533,7 +533,7 @@ issue_884: () = { }; _ = :() = { - x := new(0); + x := new(0)*; f_inout(x); if true { f_copy(x); @@ -549,7 +549,7 @@ issue_884: () = { }; _ = :() = { - x := new(0); + x := new(0)*; if true { if true { if true { @@ -562,7 +562,7 @@ issue_884: () = { }; _ = :() = { - x := new(0); + x := new(0)*; if true { if true { if true { @@ -576,7 +576,7 @@ issue_884: () = { }; _ = :() = { - x := new(0); + x := new(0)*; if true { } else { @@ -589,7 +589,7 @@ issue_884: () = { }; _ = :() = { - x := new(0); + x := new(0)*; if true { f_copy(x); } @@ -603,9 +603,9 @@ issue_884: () = { }; _ = :() = { - x := new(0); + x := new(0)*; if true { - y := new(0); + y := new(0)*; f_copy(x); f_copy(y); } @@ -620,9 +620,9 @@ issue_884: () = { }; _ = :() = { - x := new(0); + x := new(0)*; if true { - y := new(0); + y := new(0)*; if true { } else { f_copy(x); @@ -632,7 +632,7 @@ issue_884: () = { else { if true { if true { - y := new(0); + y := new(0)*; f_copy(y); f_inout(x); } @@ -642,9 +642,9 @@ issue_884: () = { }; _ = :() = { - x := new(0); + x := new(0)*; if true { - y := new(0); + y := new(0)*; if true { } else { f_copy(x); @@ -652,7 +652,7 @@ issue_884: () = { } } else { - y := new(0); + y := new(0)*; if true { if true { f_copy(x); @@ -666,13 +666,13 @@ issue_884: () = { }; _ = :() = { - x := new(0); + x := new(0)*; if true { f_copy(x); } else { if true { - x := new(0); + x := new(0)*; if true { f_inout(x); } @@ -685,10 +685,10 @@ issue_884: () = { }; _ = :() = { - x := new(0); + x := new(0)*; if true { if true { - x := new(0); + x := new(0)*; if true { f_inout(x); } @@ -704,7 +704,7 @@ issue_884: () = { }; _ = :() = { - x := new(0); + x := new(0)*; if true { f_inout(x); @@ -718,7 +718,7 @@ issue_884: () = { }; _ = :() = { - x := new(0); + x := new(0)*; if true { if true { f_inout(x); @@ -781,9 +781,9 @@ issue_888_1: (copy _: std::string, copy size: move_only_function) = { } issue_890: () = { - x := new(0); + x := new(0)*; assert(identity_copy(x)* == 0); - (x := new(0)) assert(identity(x)* == 0); + (x := new(0)*) assert(identity(x)* == 0); } issue_962: (s: ::std::string) = { @@ -803,13 +803,13 @@ enum_0: () = { underlying_type = ""; } enum_1: () = { - max_value := new(0); - min_value: std::reference_wrapper> = max_value; + max_value := new(0)*; + min_value: std::reference_wrapper> = max_value; for (0) do (copy x) { - v := new(identity_copy(x)); + v := new(identity_copy(x))*; if pred(v, min_value) { min_value = std::ref(identity(v)); // Not using 'else' will never move 'v'. } @@ -818,20 +818,20 @@ enum_1: () = { } } - y := new(false); + y := new(false)*; while identity(y)* { - v := new(0); + v := new(0)*; f_copy(v); } - z := new(false); + z := new(false)*; do { - v := new(0); + v := new(0)*; f_copy(v); } while identity(z)*; } enum_2: () = { - umax := new(0); + umax := new(0)*; if pred(umax) { } else if pred(umax) { @@ -873,14 +873,14 @@ deferred_non_copyable_2: () -> (p: std::unique_ptr) = { loops: () = { _ = :() = { - x := new(0); + x := new(0)*; for (0) do (_) f_inout(x); }; _ = :() = { - x := new(0); + x := new(0)*; for (0) next f_inout(x) do (_) @@ -888,14 +888,14 @@ loops: () = { }; _ = :() = { - x := new(0); + x := new(0)*; for (0) do (_) assert(x.get()); }; _ = :() = { - x := new(0); + x := new(0)*; if true { f_copy(x); } @@ -912,10 +912,10 @@ captures: namespace = { // Skip non captured name in function expression f: () = { - x := new(0); + x := new(0)*; f_copy(x); id := :(x) -> forward _ = x; - y := new(0); + y := new(0)*; assert(id(y)& == y&); } @@ -938,13 +938,13 @@ t: @struct type = { g: () = { _ = :() = { - x := new(0); + x := new(0)*; f_copy(x); _ = :() std::array()$; // Fails on Clang 12 (lambda in unevaluated context). }; _ = :() = { - x := new(0); + x := new(0)*; f_inout(x); _ = :() -> int = (:() x$*)$(); }; @@ -954,7 +954,7 @@ g: () = { loops_and_captures: () = { _ = :() = { - x := new(0); + x := new(0)*; f_copy(x); for (:(x) x) do (_) @@ -962,7 +962,7 @@ loops_and_captures: () = { }; _ = :() = { - x := new(0); + x := new(0)*; f_copy(x); for (:() -> _ = { using captures::x; @@ -973,7 +973,7 @@ loops_and_captures: () = { }; _ = :() = { - x := new(0); + x := new(0)*; for (:() x$*) do (_) { } @@ -992,17 +992,17 @@ types: @struct type = { skip_hidden_names: () = { _ = :() = { - x := new(0); + x := new(0)*; f_copy(x); - (copy x := new(0)) + (copy x := new(0)*) f_copy(x); }; _ = :() = { - x := new(0); + x := new(0)*; _ = :() = { _ = x$; - x := new(1); + x := new(1)*; _ = :() = { _ = x$; }; @@ -1010,17 +1010,17 @@ skip_hidden_names: () = { }; _ = :() = { - x := new(0); + x := new(0)*; f_copy(x); for (0) do (copy x) _ = identity_copy(x); - (copy x := new(0)) + (copy x := new(0)*) f_copy(x); }; _ = :() = { - x := new(0); + x := new(0)*; f_inout(x); { f_copy(x); @@ -1030,10 +1030,10 @@ skip_hidden_names: () = { }; _ = :() = { - x := new(0); + x := new(0)*; f_copy(x); _ = :() = { - static_assert(std::is_same_v>); + static_assert(std::is_same_v>); using captures::x; f_inout(x); };