blob: c197eef66e58a8942b141289f9e29ed3629c00e5 [file] [log] [blame]
Robert Griesemer8c207872011-05-25 10:26:06 -07001// errchk $G -e $D/$F.go
2
3// Copyright 2011 The Go Authors. All rights reserved.
4// Use of this source code is governed by a BSD-style
5// license that can be found in the LICENSE file.
6
7// Issue 1708, illegal cases.
8
9package p
10
11func f(x int) int { return 0 }
12func g(x interface{}) int { return 0 }
13func h(x float64) int { return 0 }
14
15// from the spec
16var (
17 s uint = 33
Ian Lance Taylor9169c272011-09-21 17:25:48 -070018 u = 1.0 << s // ERROR "invalid operation|shift of non-integer operand"
19 v float32 = 1 << s // ERROR "invalid" "as type float32"
Robert Griesemer8c207872011-05-25 10:26:06 -070020)
21
22// non-constant shift expressions
23var (
Ian Lance Taylor9169c272011-09-21 17:25:48 -070024 e1 = g(2.0 << s) // ERROR "invalid" "as type interface"
25 f1 = h(2 << s) // ERROR "invalid" "as type float64"
Robert Griesemer8c207872011-05-25 10:26:06 -070026 g1 int64 = 1.1 << s // ERROR "truncated"
27)
28
29// constant shift expressions
30const c uint = 65
31
32var (
33 a2 int = 1.0 << c // ERROR "overflow"
34 b2 = 1.0 << c // ERROR "overflow"
35 d2 = f(1.0 << c) // ERROR "overflow"
36)