OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-dev/] [or1k-gcc/] [gcc/] [testsuite/] [go.test/] [test/] [convlit.go] - Blame information for rev 700

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 700 jeremybenn
// errchk $G -e $D/$F.go
2
 
3
// Copyright 2009 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
package main
8
 
9
// explicit conversion of constants is work in progress.
10
// the ERRORs in this block are debatable, but they're what
11
// the language spec says for now.
12
var x1 = string(1)
13
var x2 string = string(1)
14
var x3 = int(1.5)     // ERROR "convert|truncate"
15
var x4 int = int(1.5) // ERROR "convert|truncate"
16
var x5 = "a" + string(1)
17
var x6 = int(1e100)      // ERROR "overflow"
18
var x7 = float32(1e1000) // ERROR "overflow"
19
 
20
// implicit conversions merit scrutiny
21
var s string
22
var bad1 string = 1  // ERROR "conver|incompatible|invalid|cannot"
23
var bad2 = s + 1     // ERROR "conver|incompatible|invalid"
24
var bad3 = s + 'a'   // ERROR "conver|incompatible|invalid"
25
var bad4 = "a" + 1   // ERROR "literals|incompatible|convert|invalid"
26
var bad5 = "a" + 'a' // ERROR "literals|incompatible|convert|invalid"
27
 
28
var bad6 int = 1.5       // ERROR "convert|truncate"
29
var bad7 int = 1e100     // ERROR "overflow"
30
var bad8 float32 = 1e200 // ERROR "overflow"
31
 
32
// but these implicit conversions are okay
33
var good1 string = "a"
34
var good2 int = 1.0
35
var good3 int = 1e9
36
var good4 float64 = 1e20
37
 
38
// explicit conversion of string is okay
39
var _ = []rune("abc")
40
var _ = []byte("abc")
41
 
42
// implicit is not
43
var _ []int = "abc"  // ERROR "cannot use|incompatible|invalid"
44
var _ []byte = "abc" // ERROR "cannot use|incompatible|invalid"
45
 
46
// named string is okay
47
type Tstring string
48
 
49
var ss Tstring = "abc"
50
var _ = []rune(ss)
51
var _ = []byte(ss)
52
 
53
// implicit is still not
54
var _ []rune = ss // ERROR "cannot use|incompatible|invalid"
55
var _ []byte = ss // ERROR "cannot use|incompatible|invalid"
56
 
57
// named slice is now ok
58
type Trune []rune
59
type Tbyte []byte
60
 
61
var _ = Trune("abc") // ok
62
var _ = Tbyte("abc") // ok
63
 
64
// implicit is still not
65
var _ Trune = "abc" // ERROR "cannot use|incompatible|invalid"
66
var _ Tbyte = "abc" // ERROR "cannot use|incompatible|invalid"

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.