1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

checker: allow EnumName(number) casts only inside unsafe{} blocks (#15932)

This commit is contained in:
Swastik Baranwal
2022-10-03 01:09:11 +05:30
committed by GitHub
parent 7993f0bf39
commit b584e1df98
32 changed files with 129 additions and 97 deletions

View File

@@ -57,7 +57,7 @@ fn temp_unix() ?Addr {
}
pub fn (a Addr) family() AddrFamily {
return AddrFamily(a.f)
return unsafe { AddrFamily(a.f) }
}
const (
@@ -206,7 +206,7 @@ pub fn resolve_ipaddrs(addr string, family AddrFamily, typ SocketType) ?[]Addr {
mut addresses := []Addr{}
for result := unsafe { results }; !isnil(result); result = result.ai_next {
match AddrFamily(result.ai_family) {
match unsafe { AddrFamily(result.ai_family) } {
.ip {
new_addr := Addr{
addr: AddrData{
@@ -239,7 +239,7 @@ pub fn resolve_ipaddrs(addr string, family AddrFamily, typ SocketType) ?[]Addr {
}
fn (a Addr) str() string {
match AddrFamily(a.f) {
match unsafe { AddrFamily(a.f) } {
.ip {
unsafe {
return a.addr.Ip.str()

View File

@@ -158,7 +158,7 @@ fn (mut c Client) expect_reply(expected ReplyCode) ? {
if str.len >= 3 {
status := str[..3].int()
if ReplyCode(status) != expected {
if unsafe { ReplyCode(status) } != expected {
return error('Received unexpected status code $status, expecting $expected')
}
} else {

View File

@@ -228,7 +228,7 @@ pub fn (mut ws Client) parse_frame_header() ?Frame {
frame.rsv1 = (buffer[0] & 0x40) == 0x40
frame.rsv2 = (buffer[0] & 0x20) == 0x20
frame.rsv3 = (buffer[0] & 0x10) == 0x10
frame.opcode = OPCode(int(buffer[0] & 0x7F))
frame.opcode = unsafe { OPCode(int(buffer[0] & 0x7F)) }
frame.has_mask = (buffer[1] & 0x80) == 0x80
frame.payload_len = buffer[1] & 0x7F
// if has mask set the byte postition where mask ends