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

reserve identifier is for *type-id* is #759

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions regression-tests/mixed-inspect-templates.cpp2
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ fun: (v : _) -> std::string = {
}

fun2: (v : _) -> std::string = {
if v is std::vector { return "std::vector"; }
if v is std::array { return "std::array"; }
if v is std::variant { return "std::variant"; }
if v is my_type { return "my_type"; }
if (v) is std::vector { return "std::vector"; }
if (v) is std::array { return "std::array"; }
if (v) is std::variant { return "std::variant"; }
if (v) is my_type { return "my_type"; }
return "unknown";
}

Expand All @@ -38,4 +38,4 @@ main: () -> int = {
std::cout << "inspected arr : (fun2(arr))$" << std::endl;
std::cout << "inspected var : (fun2(var))$" << std::endl;
std::cout << "inspected myt : (fun2(myt))$" << std::endl;
}
}
6 changes: 3 additions & 3 deletions regression-tests/mixed-inspect-values-2.cpp2
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@ main: () -> int = {
is _ = "i is out of our interest";
} << std::endl;

if i is (less_than(20)) {
if (i) is (less_than(20)) {
std::cout << "less than 20" << std::endl;
}

if i is (in(10,30)) {
if (i) is (in(10,30)) {
std::cout << "i is between 10 and 30" << std::endl;
}

Expand All @@ -39,7 +39,7 @@ main: () -> int = {
std::cout << "v is empty" << std::endl;
}

if v is (empty) {
if (v) is (empty) {
std::cout << "v is empty" << std::endl;
}
}
10 changes: 5 additions & 5 deletions regression-tests/pure2-enum.cpp2
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ main: () = {
else if skat_game::hearts == x { // ok, in either order
std::cout << "hearts";
}
else if x is (skat_game::spades) { // ok, using is
else if (x) is (skat_game::spades) { // ok, using is
std::cout << "spades";
}
else if skat_game::clubs is (x) { // ok, using is
Expand Down Expand Up @@ -95,8 +95,8 @@ main: () = {
std::cout << "f. get_raw_value() is (f. get_raw_value())$\n";
std::cout << "f2.get_raw_value() is (f2.get_raw_value())$\n";

std::cout << "f is (f2) is (f is (f2))$\n";
std::cout << "f2 is (f ) is (f2 is (f ))$\n\n";
std::cout << "(f ) is (f2) is ((f ) is (f2))$\n";
std::cout << "(f2) is (f ) is ((f2) is (f ))$\n\n";

f.clear( f2 );
f.set( file_attributes::current | f2 );
Expand All @@ -108,8 +108,8 @@ main: () = {
std::cout << "f. get_raw_value() is (f. get_raw_value())$\n";
std::cout << "f2.get_raw_value() is (f2.get_raw_value())$\n";
std::cout << "f == f2 is (f == f2 )$\n";
std::cout << "f is (f2) is (f is (f2))$\n";
std::cout << "f2 is (f ) is (f2 is (f ))$\n";
std::cout << "(f ) is (f2) is ((f ) is (f2))$\n";
std::cout << "(f2) is (f ) is ((f2) is (f ))$\n";
std::cout << "(f & f2) == f2 is ((f & f2) == f2)$\n";

std::cout << "inspecting f: " << inspect f -> std::string {
Expand Down
4 changes: 2 additions & 2 deletions regression-tests/pure2-more-wildcards.cpp2
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ main: () -> int
p: * _ = x&;
q: * const _ = p&;

if x is (less_than(20)) {
if (x) is (less_than(20)) {
std::cout << "yes, less\n";
}

if x is _ {
if (x) is _ {
std::cout << "yes, always\n";
}
}
2 changes: 1 addition & 1 deletion regression-tests/pure2-type-safety-1.cpp2
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ main: () -> int =

test_generic: ( x, msg ) = {
msgx: std::string = msg;
print( msgx + " is int? ", x is int );
print( msgx + " is int? ", (x) is int );
}

print: ( msg: std::string, b: bool ) = {
Expand Down
13 changes: 12 additions & 1 deletion source/parse.h
Original file line number Diff line number Diff line change
Expand Up @@ -6015,10 +6015,10 @@ class parser

//G is-as-expression:
//G prefix-expression
//GTODO type-id is-type-constraint
//G is-as-expression is-type-constraint
//G is-as-expression is-value-constraint
//G is-as-expression as-type-cast
//GTODO type-id is-type-constraint
//G
//G is-type-constraint
//G 'is' type-id
Expand All @@ -6033,6 +6033,17 @@ class parser
-> std::unique_ptr<is_as_expression_node>
{
auto n = std::make_unique<is_as_expression_node>();

if (
curr().type() == lexeme::Identifier
&& peek(1)
&& *peek(1) == "is"
)
{
error("(temporary alpha limitation) testing a type with 'is' is not supported yet (or perhaps use '(identifier) is' to test an expression)");
return {};
}

n->expr = prefix_expression();
if (!(n->expr)) {
return {};
Expand Down