1// errorcheck -0 -m 2 3// Copyright 2023 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 7package p 8 9import ( 10 "crypto/ecdh" 11 "crypto/rand" 12) 13 14func F(peerShare []byte) ([]byte, error) { // ERROR "leaking param: peerShare" 15 p256 := ecdh.P256() // ERROR "inlining call to ecdh.P256" 16 17 ourKey, err := p256.GenerateKey(rand.Reader) // ERROR "devirtualizing p256.GenerateKey" "inlining call to ecdh.*GenerateKey" 18 if err != nil { 19 return nil, err 20 } 21 22 peerPublic, err := p256.NewPublicKey(peerShare) // ERROR "devirtualizing p256.NewPublicKey" "inlining call to ecdh.*NewPublicKey" 23 if err != nil { 24 return nil, err 25 } 26 27 return ourKey.ECDH(peerPublic) 28} 29 30// Test that inlining doesn't break if devirtualization exposes a new 31// inlinable callee. 32 33func f() { // ERROR "can inline f" 34 var i interface{ m() } = T(0) // ERROR "T\(0\) does not escape" 35 i.m() // ERROR "devirtualizing i.m" "inlining call to T.m" 36} 37 38type T int 39 40func (T) m() { // ERROR "can inline T.m" 41 if never { 42 f() // ERROR "inlining call to f" "devirtualizing i.m" "T\(0\) does not escape" 43 } 44} 45 46var never bool 47