mirror of
https://github.com/golang/go.git
synced 2025-10-27 06:44:13 +00:00
Fixes #75617 Change-Id: Iaee7d4556db54b9999f5ba8458e7c05c11ccfc36 Reviewed-on: https://go-review.googlesource.com/c/go/+/707075 Reviewed-by: Junyang Shao <shaojunyang@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Auto-Submit: Cuong Manh Le <cuong.manhle.vn@gmail.com> Reviewed-by: Alan Donovan <adonovan@google.com>
39 lines
715 B
Go
39 lines
715 B
Go
// run
|
|
|
|
// Copyright 2025 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.
|
|
|
|
package main
|
|
|
|
// Issue #45624 is the proposal to accept new(expr) in go1.26.
|
|
// Here we test its run-time behavior.
|
|
func main() {
|
|
{
|
|
p := new(123) // untyped constant expr
|
|
if *p != 123 {
|
|
panic("wrong value")
|
|
}
|
|
}
|
|
{
|
|
x := 42
|
|
p := new(x) // non-constant expr
|
|
if *p != x {
|
|
panic("wrong value")
|
|
}
|
|
}
|
|
{
|
|
x := [2]int{123, 456}
|
|
p := new(x) // composite value
|
|
if *p != x {
|
|
panic("wrong value")
|
|
}
|
|
}
|
|
{
|
|
var i int
|
|
v := new(i > 0) // untyped expression, see issue #75617
|
|
if *v != false {
|
|
panic("wrong value")
|
|
}
|
|
}
|
|
}
|