File: splitting.go

package info (click to toggle)
golang-golang-x-exp 0.0~git20231006.7918f67-2
  • links: PTS, VCS
  • area: main
  • in suites: experimental, forky, sid, trixie
  • size: 6,492 kB
  • sloc: ansic: 1,900; objc: 276; sh: 272; asm: 48; makefile: 27
file content (77 lines) | stat: -rw-r--r-- 1,351 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
package p

// Splitting types
//
// In the old world, there is one type with two names, one of which is an alias.
// In the new world, there are two distinct types.
//
// That is an incompatible change, because client code like
//
//     var v *T1 = new(T2)
//
// will succeed in the old world, where T1 and T2 name the same type,
// but fail in the new world.

// OK: in both old and new, A, B,  and C all name the same type.
// old
type (
	A = B
	B = C
	C int
)

// new
type (
	A = B
	B int
	C = A
)

// An example of splitting:

// Old has one type, D; new has E and D.
// both
type D int

// old
type E = D

// new
// i E: changed from D to E
type E D // old D corresponds with new E
// old D also corresponds with new D: problem

// Here we have a benign split.
// f and g are the same type in old and different types in new.
// But clients have no way of constructing an expression of type f,
// so they cannot write code that breaks.

// both
type f int

var Vg g // expose g

// old
type g = f

// new
// OK: f isn't exposed
type g f

// Here we have another incompatible split, even
// though the type names are unexported. The problem
// is that both names are exposed via exported variables.

// both
type h int

var Vj j // expose j
var Vh h // expose h

// old
type j = h

// new
// i Vj: changed from h to j
// e.g. p.Vj = p.Vh
type j h