-
Notifications
You must be signed in to change notification settings - Fork 358
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
interp: fix creation of binary composite types (#1391)
* interp: fix creation of binary composite types Use direct assignment instead of reflect.Value Set method to initialize a binary composite type, as for non binary types. It ensures that a new reflect.Value is stored in the frame instead of modifying a possibly existing one, which can defeat the purpose of initializing variables in a body loop. While there, remove the need to have and use a mutex on types. Fixes #1381. * review: rework a bit the test Co-authored-by: mpl <mathieu.lonjaret@gmail.com>
- Loading branch information
Showing
3 changed files
with
65 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package main | ||
|
||
import ( | ||
"bytes" | ||
"fmt" | ||
) | ||
|
||
func main() { | ||
var bufPtrOne *bytes.Buffer | ||
var bufPtrTwo *bytes.Buffer | ||
var bufPtrThree *bytes.Buffer | ||
var bufPtrFour *bytes.Buffer | ||
|
||
for i := 0; i < 2; i++ { | ||
bufOne := bytes.Buffer{} | ||
bufTwo := &bytes.Buffer{} | ||
var bufThree bytes.Buffer | ||
bufFour := new(bytes.Buffer) | ||
|
||
if bufPtrOne == nil { | ||
bufPtrOne = &bufOne | ||
} else if bufPtrOne == &bufOne { | ||
fmt.Println("bufOne was not properly redeclared") | ||
} else { | ||
fmt.Println("bufOne is properly redeclared") | ||
} | ||
|
||
if bufPtrTwo == nil { | ||
bufPtrTwo = bufTwo | ||
} else if bufPtrTwo == bufTwo { | ||
fmt.Println("bufTwo was not properly redeclared") | ||
} else { | ||
fmt.Println("bufTwo is properly redeclared") | ||
} | ||
|
||
if bufPtrThree == nil { | ||
bufPtrThree = &bufThree | ||
} else if bufPtrThree == &bufThree { | ||
fmt.Println("bufThree was not properly redeclared") | ||
} else { | ||
fmt.Println("bufThree is properly redeclared") | ||
} | ||
|
||
if bufPtrFour == nil { | ||
bufPtrFour = bufFour | ||
} else if bufPtrFour == bufFour { | ||
fmt.Println("bufFour was not properly redeclared") | ||
} else { | ||
fmt.Println("bufFour is properly redeclared") | ||
} | ||
} | ||
} | ||
|
||
// Output: | ||
// bufOne is properly redeclared | ||
// bufTwo is properly redeclared | ||
// bufThree is properly redeclared | ||
// bufFour is properly redeclared |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters