go expr1 源码

  • 2022-07-15
  • 浏览 (1169)

golang expr1 代码

文件路径:/src/cmd/compile/internal/types2/testdata/check/expr1.go

// Copyright 2012 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

// binary expressions

package expr1

type mybool bool

func _(x, y bool, z mybool) {
	x = x || y
	x = x || true
	x = x || false
	x = x && y
	x = x && true
	x = x && false

	z = z /* ERROR mismatched types */ || y
	z = z || true
	z = z || false
	z = z /* ERROR mismatched types */ && y
	z = z && true
	z = z && false
}

type myint int

func _(x, y int, z myint) {
	x = x + 1
	x = x + 1.0
	x = x + 1.1 // ERROR truncated to int
	x = x + y
	x = x - y
	x = x * y
	x = x / y
	x = x % y
	x = x << y
	x = x >> y

	z = z + 1
	z = z + 1.0
	z = z + 1.1 // ERROR truncated to int
	z = z /* ERROR mismatched types */ + y
	z = z /* ERROR mismatched types */ - y
	z = z /* ERROR mismatched types */ * y
	z = z /* ERROR mismatched types */ / y
	z = z /* ERROR mismatched types */ % y
	z = z << y
	z = z >> y
}

type myuint uint

func _(x, y uint, z myuint) {
	x = x + 1
	x = x + - /* ERROR overflows uint */ 1
	x = x + 1.0
	x = x + 1.1 // ERROR truncated to uint
	x = x + y
	x = x - y
	x = x * y
	x = x / y
	x = x % y
	x = x << y
	x = x >> y

	z = z + 1
	z = x + - /* ERROR overflows uint */ 1
	z = z + 1.0
	z = z + 1.1 // ERROR truncated to uint
	z = z /* ERROR mismatched types */ + y
	z = z /* ERROR mismatched types */ - y
	z = z /* ERROR mismatched types */ * y
	z = z /* ERROR mismatched types */ / y
	z = z /* ERROR mismatched types */ % y
	z = z << y
	z = z >> y
}

type myfloat64 float64

func _(x, y float64, z myfloat64) {
	x = x + 1
	x = x + -1
	x = x + 1.0
	x = x + 1.1
	x = x + y
	x = x - y
	x = x * y
	x = x / y
	x = x /* ERROR not defined */ % y
	x = x /* ERROR operand x .* must be integer */ << y
	x = x /* ERROR operand x .* must be integer */ >> y

	z = z + 1
	z = z + -1
	z = z + 1.0
	z = z + 1.1
	z = z /* ERROR mismatched types */ + y
	z = z /* ERROR mismatched types */ - y
	z = z /* ERROR mismatched types */ * y
	z = z /* ERROR mismatched types */ / y
	z = z /* ERROR mismatched types */ % y
	z = z /* ERROR operand z .* must be integer */ << y
	z = z /* ERROR operand z .* must be integer */ >> y
}

type mystring string

func _(x, y string, z mystring) {
	x = x + "foo"
	x = x /* ERROR not defined */ - "foo"
	x = x + 1 // ERROR mismatched types string and untyped int
	x = x + y
	x = x /* ERROR not defined */ - y
	x = x * 10 // ERROR mismatched types string and untyped int
}

func f() (a, b int) { return }

func _(x int) {
	_ = f /* ERROR 2-valued f */ () + 1
	_ = x + f /* ERROR 2-valued f */ ()
	_ = f /* ERROR 2-valued f */ () + f
	_ = f /* ERROR 2-valued f */ () + f /* ERROR 2-valued f */ ()
}

相关信息

go 源码目录

相关文章

go blank 源码

go builtins0 源码

go builtins1 源码

go chans 源码

go compliterals 源码

go const0 源码

go const1 源码

go constdecl 源码

go conversions0 源码

go conversions1 源码

0  赞