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

Incorrect assertion fail #20314

Closed
MCausc78 opened this issue Dec 30, 2023 · 0 comments · Fixed by #20424
Closed

Incorrect assertion fail #20314

MCausc78 opened this issue Dec 30, 2023 · 0 comments · Fixed by #20424
Assignees
Labels
Bug This tag is applied to issues which reports bugs. Option Type Bugs/feature requests, that are related to `?Type`. Unit: cgen Bugs/feature requests, that are related to the default C generating backend.

Comments

@MCausc78
Copy link
Contributor

MCausc78 commented Dec 30, 2023

Describe the bug

<title>

Reproduction Steps

import x.json2

pub struct PartialEmoji {
pub:
	id       ?int
	name     string
	animated bool
}

pub fn PartialEmoji.parse(j json2.Any) !PartialEmoji {
	match j {
		map[string]json2.Any {
			return PartialEmoji{
				id: if s := j['id'] {
					if s !is json2.Null {
						?int(s.int())
					} else {
						none
					}
				} else {
					none
				}
				name: j['name']! as string
				animated: if b := j['animated'] {
					b as bool
				} else {
					false
				}
			}
		}
		else {
			return error('expected partial emoji to be object, got ${j.type_name()}')
		}
	}
}

pub enum ButtonStyle {
	primary   = 1
	secondary
	success
	danger
	link
}

pub struct Button {
pub:
	style ButtonStyle = .secondary
	label ?string
	emoji ?PartialEmoji
	custom_id ?string
	url ?string
	disabled ?bool
}


pub fn Button.parse(j json2.Any) !Button {
	match j {
		map[string]json2.Any {
			return Button{
				style: unsafe { ButtonStyle(j['style']!.int()) }
				label: if s := j['label'] {
					?string(s as string)
				} else {
					none
				}
				emoji: if o := j['emoji'] {
					?PartialEmoji(PartialEmoji.parse(o)!)
				} else {
					none
				}
				custom_id: if s := j['custom_id'] {
					?string(s as string)
				} else {
					none
				}
				url: if s := j['url'] {
					?string(s as string)
				} else {
					none
				}
				disabled: if b := j['disabled'] {
					?bool(b as bool)
				} else {
					none
				}
			}
		}
		else {
			return error('expected button to be object, got ${j.type_name()}')
		}
	}
}

fn main() {
	assert Button.parse({'style': json2.Any(2)}) or {
		panic('That case should not return error: ${err}')
	} == Button{
		style: .secondary
	} 
}

Expected Behavior

Successful execution

Current Behavior

test.v:95: FAIL: fn main.main: assert Button.parse(map{ 'style': x.json2.Any(2) }) == main.Button{....}
   left value: Button.parse(map{ 'style': x.json2.Any(2) }) = Button{
    style: secondary
    label: Option(none)
    emoji: Option(none)
    custom_id: Option(none)
    url: Option(none)
    disabled: Option(none)
}
  right value: main.Button{....} = Button{
    style: secondary
    label: Option(none)
    emoji: Option(none)
    custom_id: Option(none)
    url: Option(none)
    disabled: Option(none)
}
V panic: Assertion failed...
v hash: 053d2be
C:/Users/mclr/AppData/Local/Temp/v_0/test.15761995003000066849.tmp.c:8174: at _v_panic: Backtrace
C:/Users/mclr/AppData/Local/Temp/v_0/test.15761995003000066849.tmp.c:18015: by main__main
C:/Users/mclr/AppData/Local/Temp/v_0/test.15761995003000066849.tmp.c:18130: by wmain
0049f388 : by ???
0049f4eb : by ???
7ffb8d4253e0 : by ???

Possible Solution

No response

Additional Information/Context

The problem caused by emoji

V version

V 0.4.3 053d2be

Environment details (OS name and version, etc.)

V full version: V 0.4.3 57a33c3.053d2be
OS: windows, Microsoft Windows 11 Pro v22000 64-bit
Processor: 12 cpus, 64bit, little endian, 

getwd: D:\Games\Proekti\V\interactions
vexe: D:\Games\Proekti\V\v\v.exe
vexe mtime: 2023-12-30 11:20:18

vroot: OK, value: D:\Games\Proekti\V\v
VMODULES: OK, value: C:\Users\mclr\.vmodules
VTMP: OK, value: C:\Users\mclr\AppData\Local\Temp\v_0

Git version: git version 2.37.0.windows.1
Git vroot status: weekly.2023.52-27-g053d2bec
.git/config present: true

CC version:
thirdparty/tcc status: thirdparty-windows-amd64 a39eb79b

Note

You can use the 👍 reaction to increase the issue's priority for developers.

Please note that only the 👍 reaction to the issue itself counts as a vote.
Other reactions and those to comments will not be taken into account.

@MCausc78 MCausc78 added the Bug This tag is applied to issues which reports bugs. label Dec 30, 2023
@felipensp felipensp self-assigned this Jan 7, 2024
@felipensp felipensp added Unit: cgen Bugs/feature requests, that are related to the default C generating backend. Option Type Bugs/feature requests, that are related to `?Type`. labels Jan 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug This tag is applied to issues which reports bugs. Option Type Bugs/feature requests, that are related to `?Type`. Unit: cgen Bugs/feature requests, that are related to the default C generating backend.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants