| 1 |
|
| 2 |
-- go.mod -- |
| 3 |
module example.com |
| 4 |
go 1.18 |
| 5 |
|
| 6 |
-- template/template.go -- |
| 7 |
package template |
| 8 |
|
| 9 |
import "fmt" |
| 10 |
|
| 11 |
// Test of semantic (not syntactic) matching of basic literals. |
| 12 |
|
| 13 |
func before() (int, error) { return fmt.Println(123, "a") } |
| 14 |
func after() (int, error) { return fmt.Println(456, "!") } |
| 15 |
|
| 16 |
-- in/d1/d1.go -- |
| 17 |
package d1 |
| 18 |
|
| 19 |
import "fmt" |
| 20 |
|
| 21 |
func example() { |
| 22 |
fmt.Println(123, "a") // match |
| 23 |
fmt.Println(0x7b, `a`) // match |
| 24 |
fmt.Println(0173, "\x61") // match |
| 25 |
fmt.Println(100+20+3, "a"+"") // no match: constant expressions, but not basic literals |
| 26 |
} |
| 27 |
|
| 28 |
-- out/d1/d1.go -- |
| 29 |
package d1 |
| 30 |
|
| 31 |
import "fmt" |
| 32 |
|
| 33 |
func example() { |
| 34 |
fmt.Println(456, "!") // match |
| 35 |
fmt.Println(456, "!") // match |
| 36 |
fmt.Println(456, "!") // match |
| 37 |
fmt.Println(100+20+3, "a"+"") // no match: constant expressions, but not basic literals |
| 38 |
} |