codekingpro/portable-devtools
114k
1// errorcheck2 3// Copyright 2025 The Go Authors. All rights reserved.4// Use of this source code is governed by a BSD-style5// license that can be found in the LICENSE file.6 7// Test weak pointers.8 9package p10 11import (12 "runtime"13 "weak"14)15 16// Adapted from example in https://github.com/golang/go/issues/67552#issuecomment-263966122017func conversion() {18 p := "hello"19 a := weak.Make(&p)20 b := (weak.Pointer[*byte])(a) // ERROR "cannot convert a \(variable of struct type weak\.Pointer\[string\]\) to type weak.Pointer\[\*byte\]"21 c := b.Value()22 println(**c)23 runtime.KeepAlive(p)24}25 