all: cleanup smartcasts in the compiler (#13639)
							parent
							
								
									4e7db5bab0
								
							
						
					
					
						commit
						288b13b51d
					
				| 
						 | 
					@ -3544,12 +3544,9 @@ pub fn (mut c Checker) prefix_expr(mut node ast.PrefixExpr) ast.Type {
 | 
				
			||||||
		for mut expr is ast.ParExpr {
 | 
							for mut expr is ast.ParExpr {
 | 
				
			||||||
			expr = expr.expr
 | 
								expr = expr.expr
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		match expr {
 | 
							if expr in [ast.BoolLiteral, ast.CallExpr, ast.CharLiteral, ast.FloatLiteral,
 | 
				
			||||||
			ast.BoolLiteral, ast.CallExpr, ast.CharLiteral, ast.FloatLiteral, ast.IntegerLiteral,
 | 
								ast.IntegerLiteral, ast.InfixExpr, ast.StringLiteral, ast.StringInterLiteral] {
 | 
				
			||||||
			ast.InfixExpr, ast.StringLiteral, ast.StringInterLiteral {
 | 
								c.error('cannot take the address of $expr', node.pos)
 | 
				
			||||||
				c.error('cannot take the address of $expr', node.pos)
 | 
					 | 
				
			||||||
			}
 | 
					 | 
				
			||||||
			else {}
 | 
					 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		if mut node.right is ast.IndexExpr {
 | 
							if mut node.right is ast.IndexExpr {
 | 
				
			||||||
			typ_sym := c.table.sym(node.right.left_type)
 | 
								typ_sym := c.table.sym(node.right.left_type)
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -103,10 +103,9 @@ fn (mut c Checker) for_in_stmt(mut node ast.ForInStmt) {
 | 
				
			||||||
				value_type = value_type.ref()
 | 
									value_type = value_type.ref()
 | 
				
			||||||
				match node.cond {
 | 
									match node.cond {
 | 
				
			||||||
					ast.Ident {
 | 
										ast.Ident {
 | 
				
			||||||
						if node.cond.obj is ast.Var {
 | 
											if mut node.cond.obj is ast.Var {
 | 
				
			||||||
							obj := node.cond.obj as ast.Var
 | 
												if !node.cond.obj.is_mut {
 | 
				
			||||||
							if !obj.is_mut {
 | 
													c.error('`$node.cond.obj.name` is immutable, it cannot be changed',
 | 
				
			||||||
								c.error('`$obj.name` is immutable, it cannot be changed',
 | 
					 | 
				
			||||||
									node.cond.pos)
 | 
														node.cond.pos)
 | 
				
			||||||
							}
 | 
												}
 | 
				
			||||||
						}
 | 
											}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -684,10 +684,8 @@ fn (mut g Gen) sql_select(node ast.SqlExpr, expr string, left string) {
 | 
				
			||||||
				name := sel
 | 
									name := sel
 | 
				
			||||||
				s := g.table.find_type_idx('orm.Primitive')
 | 
									s := g.table.find_type_idx('orm.Primitive')
 | 
				
			||||||
				if s != 0 {
 | 
									if s != 0 {
 | 
				
			||||||
					if ident.info is ast.IdentVar {
 | 
										if mut ident.info is ast.IdentVar {
 | 
				
			||||||
						mut info := ident.info as ast.IdentVar
 | 
											ident.info.typ = s
 | 
				
			||||||
						info.typ = s
 | 
					 | 
				
			||||||
						ident.info = info
 | 
					 | 
				
			||||||
					}
 | 
										}
 | 
				
			||||||
				}
 | 
									}
 | 
				
			||||||
				ident.name = name
 | 
									ident.name = name
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -159,10 +159,9 @@ fn (mut p Parser) partial_assign_stmt(left []ast.Expr, left_comments []ast.Comme
 | 
				
			||||||
						return p.error_with_pos('redefinition of `$lx.name`', lx.pos)
 | 
											return p.error_with_pos('redefinition of `$lx.name`', lx.pos)
 | 
				
			||||||
					}
 | 
										}
 | 
				
			||||||
					mut share := ast.ShareType(0)
 | 
										mut share := ast.ShareType(0)
 | 
				
			||||||
					if lx.info is ast.IdentVar {
 | 
										if mut lx.info is ast.IdentVar {
 | 
				
			||||||
						iv := lx.info as ast.IdentVar
 | 
											share = lx.info.share
 | 
				
			||||||
						share = iv.share
 | 
											if lx.info.is_static {
 | 
				
			||||||
						if iv.is_static {
 | 
					 | 
				
			||||||
							if !p.pref.translated && !p.is_translated && !p.pref.is_fmt
 | 
												if !p.pref.translated && !p.is_translated && !p.pref.is_fmt
 | 
				
			||||||
								&& !p.inside_unsafe_fn {
 | 
													&& !p.inside_unsafe_fn {
 | 
				
			||||||
								return p.error_with_pos('static variables are supported only in translated mode or in [unsafe] fn',
 | 
													return p.error_with_pos('static variables are supported only in translated mode or in [unsafe] fn',
 | 
				
			||||||
| 
						 | 
					@ -170,7 +169,7 @@ fn (mut p Parser) partial_assign_stmt(left []ast.Expr, left_comments []ast.Comme
 | 
				
			||||||
							}
 | 
												}
 | 
				
			||||||
							is_static = true
 | 
												is_static = true
 | 
				
			||||||
						}
 | 
											}
 | 
				
			||||||
						if iv.is_volatile {
 | 
											if lx.info.is_volatile {
 | 
				
			||||||
							is_volatile = true
 | 
												is_volatile = true
 | 
				
			||||||
						}
 | 
											}
 | 
				
			||||||
					}
 | 
										}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -31,17 +31,16 @@ fn (mut p Parser) sql_expr() ast.Expr {
 | 
				
			||||||
		p.next()
 | 
							p.next()
 | 
				
			||||||
		where_expr = p.expr(0)
 | 
							where_expr = p.expr(0)
 | 
				
			||||||
		// `id == x` means that a single object is returned
 | 
							// `id == x` means that a single object is returned
 | 
				
			||||||
		if !is_count && where_expr is ast.InfixExpr {
 | 
							if !is_count && mut where_expr is ast.InfixExpr {
 | 
				
			||||||
			e := where_expr as ast.InfixExpr
 | 
								if where_expr.op == .eq && mut where_expr.left is ast.Ident {
 | 
				
			||||||
			if e.op == .eq && e.left is ast.Ident {
 | 
									if where_expr.left.name == 'id' {
 | 
				
			||||||
				if e.left.name == 'id' {
 | 
					 | 
				
			||||||
					query_one = true
 | 
										query_one = true
 | 
				
			||||||
				}
 | 
									}
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
			if e.right is ast.Ident {
 | 
								if mut where_expr.right is ast.Ident {
 | 
				
			||||||
				if !p.scope.known_var(e.right.name) {
 | 
									if !p.scope.known_var(where_expr.right.name) {
 | 
				
			||||||
					p.check_undefined_variables([e.left], e.right) or {
 | 
										p.check_undefined_variables([where_expr.left], where_expr.right) or {
 | 
				
			||||||
						return p.error_with_pos(err.msg(), e.right.pos)
 | 
											return p.error_with_pos(err.msg(), where_expr.right.pos)
 | 
				
			||||||
					}
 | 
										}
 | 
				
			||||||
				}
 | 
									}
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -935,8 +935,8 @@ pub fn (mut t Transformer) if_expr(mut node ast.IfExpr) ast.Expr {
 | 
				
			||||||
			stmt = t.stmt(mut stmt)
 | 
								stmt = t.stmt(mut stmt)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
			if i == branch.stmts.len - 1 {
 | 
								if i == branch.stmts.len - 1 {
 | 
				
			||||||
				if stmt is ast.ExprStmt {
 | 
									if mut stmt is ast.ExprStmt {
 | 
				
			||||||
					expr := (stmt as ast.ExprStmt).expr
 | 
										expr := stmt.expr
 | 
				
			||||||
 | 
					
 | 
				
			||||||
					match expr {
 | 
										match expr {
 | 
				
			||||||
						ast.IfExpr {
 | 
											ast.IfExpr {
 | 
				
			||||||
| 
						 | 
					@ -976,8 +976,8 @@ pub fn (mut t Transformer) match_expr(mut node ast.MatchExpr) ast.Expr {
 | 
				
			||||||
			stmt = t.stmt(mut stmt)
 | 
								stmt = t.stmt(mut stmt)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
			if i == branch.stmts.len - 1 {
 | 
								if i == branch.stmts.len - 1 {
 | 
				
			||||||
				if stmt is ast.ExprStmt {
 | 
									if mut stmt is ast.ExprStmt {
 | 
				
			||||||
					expr := (stmt as ast.ExprStmt).expr
 | 
										expr := stmt.expr
 | 
				
			||||||
 | 
					
 | 
				
			||||||
					match expr {
 | 
										match expr {
 | 
				
			||||||
						ast.IfExpr {
 | 
											ast.IfExpr {
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue