mirror of
https://github.com/Ed94/Odin.git
synced 2026-07-30 11:20:08 +00:00
Remove switch in in favour of switch _ in
This commit is contained in:
+2
-2
@@ -471,7 +471,7 @@ join_port :: proc(address_or_host: string, port: int, allocator := context.alloc
|
|||||||
// hostname
|
// hostname
|
||||||
fmt.sbprintf(&b, "%v:%v", addr_or_host, port)
|
fmt.sbprintf(&b, "%v:%v", addr_or_host, port)
|
||||||
} else {
|
} else {
|
||||||
switch in addr {
|
switch _ in addr {
|
||||||
case IP4_Address:
|
case IP4_Address:
|
||||||
fmt.sbprintf(&b, "%v:%v", address_to_string(addr), port)
|
fmt.sbprintf(&b, "%v:%v", address_to_string(addr), port)
|
||||||
case IP6_Address:
|
case IP6_Address:
|
||||||
@@ -606,7 +606,7 @@ to_string :: proc{address_to_string, endpoint_to_string}
|
|||||||
|
|
||||||
|
|
||||||
family_from_address :: proc(addr: Address) -> Address_Family {
|
family_from_address :: proc(addr: Address) -> Address_Family {
|
||||||
switch in addr {
|
switch _ in addr {
|
||||||
case IP4_Address: return .IP4
|
case IP4_Address: return .IP4
|
||||||
case IP6_Address: return .IP6
|
case IP6_Address: return .IP6
|
||||||
case:
|
case:
|
||||||
|
|||||||
+3
-3
@@ -96,7 +96,7 @@ resolve :: proc(hostname_and_maybe_port: string) -> (ep4, ep6: Endpoint, err: Ne
|
|||||||
switch t in target {
|
switch t in target {
|
||||||
case Endpoint:
|
case Endpoint:
|
||||||
// NOTE(tetra): The hostname was actually an IP address; nothing to resolve, so just return it.
|
// NOTE(tetra): The hostname was actually an IP address; nothing to resolve, so just return it.
|
||||||
switch in t.address {
|
switch _ in t.address {
|
||||||
case IP4_Address: ep4 = t
|
case IP4_Address: ep4 = t
|
||||||
case IP6_Address: ep6 = t
|
case IP6_Address: ep6 = t
|
||||||
case: unreachable()
|
case: unreachable()
|
||||||
@@ -122,7 +122,7 @@ resolve_ip4 :: proc(hostname_and_maybe_port: string) -> (ep4: Endpoint, err: Net
|
|||||||
switch t in target {
|
switch t in target {
|
||||||
case Endpoint:
|
case Endpoint:
|
||||||
// NOTE(tetra): The hostname was actually an IP address; nothing to resolve, so just return it.
|
// NOTE(tetra): The hostname was actually an IP address; nothing to resolve, so just return it.
|
||||||
switch in t.address {
|
switch _ in t.address {
|
||||||
case IP4_Address:
|
case IP4_Address:
|
||||||
return t, nil
|
return t, nil
|
||||||
case IP6_Address:
|
case IP6_Address:
|
||||||
@@ -149,7 +149,7 @@ resolve_ip6 :: proc(hostname_and_maybe_port: string) -> (ep6: Endpoint, err: Net
|
|||||||
switch t in target {
|
switch t in target {
|
||||||
case Endpoint:
|
case Endpoint:
|
||||||
// NOTE(tetra): The hostname was actually an IP address; nothing to resolve, so just return it.
|
// NOTE(tetra): The hostname was actually an IP address; nothing to resolve, so just return it.
|
||||||
switch in t.address {
|
switch _ in t.address {
|
||||||
case IP4_Address:
|
case IP4_Address:
|
||||||
err = .Unable_To_Resolve
|
err = .Unable_To_Resolve
|
||||||
return
|
return
|
||||||
|
|||||||
@@ -77,7 +77,7 @@ clone_node :: proc(node: ^Node) -> ^Node {
|
|||||||
align = elem.align
|
align = elem.align
|
||||||
}
|
}
|
||||||
|
|
||||||
#partial switch in node.derived {
|
#partial switch _ in node.derived {
|
||||||
case ^Package, ^File:
|
case ^Package, ^File:
|
||||||
panic("Cannot clone this node type")
|
panic("Cannot clone this node type")
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1091,7 +1091,7 @@ parse_attribute :: proc(p: ^Parser, tok: tokenizer.Token, open_kind, close_kind:
|
|||||||
|
|
||||||
parse_foreign_block_decl :: proc(p: ^Parser) -> ^ast.Stmt {
|
parse_foreign_block_decl :: proc(p: ^Parser) -> ^ast.Stmt {
|
||||||
decl := parse_stmt(p)
|
decl := parse_stmt(p)
|
||||||
#partial switch in decl.derived_stmt {
|
#partial switch _ in decl.derived_stmt {
|
||||||
case ^ast.Empty_Stmt, ^ast.Bad_Stmt, ^ast.Bad_Decl:
|
case ^ast.Empty_Stmt, ^ast.Bad_Stmt, ^ast.Bad_Decl:
|
||||||
// Ignore
|
// Ignore
|
||||||
return nil
|
return nil
|
||||||
|
|||||||
@@ -1354,13 +1354,13 @@ partial_switch :: proc() {
|
|||||||
{ // union
|
{ // union
|
||||||
Foo :: union {int, bool}
|
Foo :: union {int, bool}
|
||||||
f: Foo = 123
|
f: Foo = 123
|
||||||
switch in f {
|
switch _ in f {
|
||||||
case int: fmt.println("int")
|
case int: fmt.println("int")
|
||||||
case bool: fmt.println("bool")
|
case bool: fmt.println("bool")
|
||||||
case:
|
case:
|
||||||
}
|
}
|
||||||
|
|
||||||
#partial switch in f {
|
#partial switch _ in f {
|
||||||
case bool: fmt.println("bool")
|
case bool: fmt.println("bool")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+4
-1
@@ -4382,7 +4382,10 @@ gb_internal Ast *parse_switch_stmt(AstFile *f) {
|
|||||||
f->expr_level = -1;
|
f->expr_level = -1;
|
||||||
defer (f->expr_level = prev_level);
|
defer (f->expr_level = prev_level);
|
||||||
|
|
||||||
if (allow_token(f, Token_in)) {
|
if (f->curr_token.kind == Token_in) {
|
||||||
|
Token in_token = expect_token(f, Token_in);
|
||||||
|
syntax_error(in_token, "Prefer 'switch _ in' over 'switch in'");
|
||||||
|
|
||||||
auto lhs = array_make<Ast *>(heap_allocator(), 0, 1);
|
auto lhs = array_make<Ast *>(heap_allocator(), 0, 1);
|
||||||
auto rhs = array_make<Ast *>(heap_allocator(), 0, 1);
|
auto rhs = array_make<Ast *>(heap_allocator(), 0, 1);
|
||||||
Token blank_ident = token;
|
Token blank_ident = token;
|
||||||
|
|||||||
Reference in New Issue
Block a user