Commit 27970af5 authored by Robert Griesemer's avatar Robert Griesemer

go/types: print, println accept 0 or more arguments

R=adonovan
CC=golang-dev
https://golang.org/cl/7304089
parent 17377ab6
...@@ -41,7 +41,7 @@ func (check *checker) builtin(x *operand, call *ast.CallExpr, bin *builtin, iota ...@@ -41,7 +41,7 @@ func (check *checker) builtin(x *operand, call *ast.CallExpr, bin *builtin, iota
if n > 0 { if n > 0 {
arg0 = args[0] arg0 = args[0]
switch id { switch id {
case _Make, _New, _Trace: case _Make, _New, _Print, _Println, _Trace:
// respective cases below do the work // respective cases below do the work
default: default:
// argument must be an expression // argument must be an expression
...@@ -301,9 +301,15 @@ func (check *checker) builtin(x *operand, call *ast.CallExpr, bin *builtin, iota ...@@ -301,9 +301,15 @@ func (check *checker) builtin(x *operand, call *ast.CallExpr, bin *builtin, iota
x.mode = variable x.mode = variable
x.typ = &Pointer{Base: resultTyp} x.typ = &Pointer{Base: resultTyp}
case _Panic, _Print, _Println: case _Panic:
for _, arg := range args[1:] { x.mode = novalue
case _Print, _Println:
for _, arg := range args {
check.expr(x, arg, nil, -1) check.expr(x, arg, nil, -1)
if x.mode == invalid {
goto Error
}
} }
x.mode = novalue x.mode = novalue
......
...@@ -214,6 +214,32 @@ func _new() { ...@@ -214,6 +214,32 @@ func _new() {
new /* ERROR "not used" */ (int) new /* ERROR "not used" */ (int)
} }
func _panic() {
panic /* ERROR "arguments" */ ()
panic /* ERROR "arguments" */ (1, 2)
panic(0)
panic("foo")
panic(false)
}
func _print() {
print()
print(1)
print(1, 2)
print("foo")
print(2.718281828)
print(false)
}
func _println() {
println()
println(1)
println(1, 2)
println("foo")
println(2.718281828)
println(false)
}
func _real() { func _real() {
var f32 float32 var f32 float32
var f64 float64 var f64 float64
......
...@@ -73,8 +73,8 @@ var predeclaredFunctions = [...]*builtin{ ...@@ -73,8 +73,8 @@ var predeclaredFunctions = [...]*builtin{
{_Make, "make", 1, true, false}, {_Make, "make", 1, true, false},
{_New, "new", 1, false, false}, {_New, "new", 1, false, false},
{_Panic, "panic", 1, false, true}, {_Panic, "panic", 1, false, true},
{_Print, "print", 1, true, true}, {_Print, "print", 0, true, true},
{_Println, "println", 1, true, true}, {_Println, "println", 0, true, true},
{_Real, "real", 1, false, false}, {_Real, "real", 1, false, false},
{_Recover, "recover", 0, false, true}, {_Recover, "recover", 0, false, true},
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment