@@ -3134,8 +3134,12 @@ fn (mut c Checker) ident(mut node ast.Ident) ast.Type {
31343134 info := node.info as ast.IdentVar
31353135 // Got a var with type T, return current generic type
31363136 if node.or_expr.kind != .absent {
3137- if ! info.typ.has_flag (.option) && node.or_expr.kind == .propagate_option {
3138- c.error ('cannot use `?` on non-option variable' , node.pos)
3137+ if ! info.typ.has_flag (.option) {
3138+ if node.or_expr.kind == .propagate_option {
3139+ c.error ('cannot use `?` on non-option variable' , node.pos)
3140+ } else if node.or_expr.kind == .block {
3141+ c.error ('cannot use `or {}` block on non-option variable' , node.pos)
3142+ }
31393143 }
31403144 unwrapped_typ := info.typ.clear_flag (.option).clear_flag (.result)
31413145 c.expected_or_type = unwrapped_typ
@@ -3228,8 +3232,13 @@ fn (mut c Checker) ident(mut node ast.Ident) ast.Type {
32283232 if node.or_expr.kind == .absent {
32293233 return typ.clear_flag (.result)
32303234 }
3231- if ! typ.has_flag (.option) && node.or_expr.kind == .propagate_option {
3232- c.error ('cannot use `?` on non-option variable' , node.pos)
3235+ if ! typ.has_flag (.option) {
3236+ if node.or_expr.kind == .propagate_option {
3237+ c.error ('cannot use `?` on non-option variable' , node.pos)
3238+ } else if node.or_expr.kind == .block {
3239+ c.error ('cannot use `or {}` block on non-option variable' ,
3240+ node.pos)
3241+ }
32333242 }
32343243 unwrapped_typ := typ.clear_flag (.option).clear_flag (.result)
32353244 c.expected_or_type = unwrapped_typ
0 commit comments