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

parser: fix parsing map value inside or expr (fix #12164) #22180

Merged
merged 1 commit into from
Sep 8, 2024

Conversation

yuyi98
Copy link
Member

@yuyi98 yuyi98 commented Sep 8, 2024

This PR fix parsing map value inside or expr (fix #12164).

  • Fix parsing map value inside or expr.
  • Add test.
struct MyError {
  msg string
  code int
}

fn (my MyError) msg() string {
	return my.msg
}

fn (my MyError) code() int {
	return my.code
}

type MapString = map[string]string | int

fn f() ?MapString {
  return MyError{msg: 'String Error'}
}

fn main() {
  println(f() or { { 'abc': err.msg() } })
}

PS D:\Test\v\tt1> v run .
MapString({'abc': 'String Error'})

Copy link
Member

@spytheman spytheman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Excellent work.

@spytheman spytheman merged commit 3300e59 into vlang:master Sep 8, 2024
75 checks passed
@yuyi98 yuyi98 deleted the fix_parser_map_expr_stmt branch September 8, 2024 09:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Bug using map on or error handling
2 participants