Source file test/newexpr.go
1 // run 2 3 // Copyright 2025 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 // Issue #45624 is the proposal to accept new(expr) in go1.26. 10 // Here we test its run-time behavior. 11 func main() { 12 { 13 p := new(123) // untyped constant expr 14 if *p != 123 { 15 panic("wrong value") 16 } 17 } 18 { 19 x := 42 20 p := new(x) // non-constant expr 21 if *p != x { 22 panic("wrong value") 23 } 24 } 25 { 26 x := [2]int{123, 456} 27 p := new(x) // composite value 28 if *p != x { 29 panic("wrong value") 30 } 31 } 32 { 33 var i int 34 v := new(i > 0) // untyped expression, see issue #75617 35 if *v != false { 36 panic("wrong value") 37 } 38 } 39 } 40