[{"id":"goadvanced-001","courseId":"go-advanced","domain":"types-values","topic":"Underlying types","prompt":"Two named slice types share the same underlying type. Given these declarations, which assignment compiles with no conversion?","hint":"Look at whether each side of the assignment is a named type.","explain":"Every type has an underlying type, and assignment compares underlying types. Whether a type is named also matters when the underlying types are the same.","source":"https://go.dev/ref/spec#Underlying_types","interaction":{"type":"single"},"options":[{"id":"a","text":"var t IntList = []int{1, 2}","why":"An unnamed type literal can be assigned to a named type with the same underlying type."},{"id":"b","text":"var t Scores = s","whyNot":"IntList and Scores are both named, so matching underlying types are not enough; a conversion is needed."},{"id":"c","text":"var t IntList = Scores{3}","whyNot":"Scores and IntList are both named types, so this assignment also needs an explicit conversion."},{"id":"d","text":"var t map[string]int = s","whyNot":"The underlying types differ: a slice is not a map, so nothing matches."}],"answer":"a","explanation":"A value is assignable to a type when the underlying types are identical and at least one of the two types is not a named type.","concept":"A value is assignable to a type when the underlying types are identical and at least one of the two types is not a named type.","rev":1,"updatedAt":"2026-10-23","kind":"scenario","code":"type IntList []int\ntype Scores []int\n\nvar s IntList","takeaways":["Two named types with the same underlying type still need a conversion to assign to each other."]},{"id":"goadvanced-002","courseId":"go-advanced","domain":"types-values","topic":"Constraint-only interfaces","prompt":"Given these declarations, which TWO statements about constraint interfaces are correct?","hint":"Consider which interfaces may be used as variable types, and what a ~ term matches.","explain":"A constraint interface lists type terms that a type argument must match. Terms like ~int match by underlying type, and some interfaces are legal only as constraints, not as variable types.","source":"https://go.dev/ref/spec#General_interfaces","interaction":{"type":"multiple","tellCount":true},"options":[{"id":"a","text":"Number accepts Count, because Count's underlying type is int.","why":"The term ~int matches every type whose underlying type is int, and Count is one of them."},{"id":"b","text":"interface{ int; string } has an empty type set, so no type satisfies it.","why":"No type is both an int and a string, so the type set is empty and nothing fits the constraint."},{"id":"c","text":"var n Number is valid, because Number is an ordinary interface.","whyNot":"Number has type terms, so it is constraint-only and cannot be the type of a variable."},{"id":"d","text":"Number accepts float32, because both are floating-point types.","whyNot":"The term ~float64 matches only types whose underlying type is float64; float32 is a different type."},{"id":"e","text":"The union int | ~int is legal, since both terms name int.","whyNot":"Terms in a union must have disjoint type sets; ~int already includes int, so these overlap and are illegal."},{"id":"f","text":"A constraint may put comparable in a union, as in comparable | int.","whyNot":"The implementation restriction forbids comparable inside a union with more than one term."}],"answer":"ab","explanation":"A term ~T matches every type whose underlying type is T. An interface with an empty type set is satisfied by no type, and constraint-only interfaces cannot be variable types.","concept":"A term ~T matches every type whose underlying type is T. An interface with an empty type set is satisfied by no type, and constraint-only interfaces cannot be variable types.","rev":1,"updatedAt":"2026-10-23","kind":"scenario","code":"type Count int\n\ntype Number interface {\n    ~int | ~float64\n}","takeaways":["A ~T term matches every named type whose underlying type is T, so a constraint can accept custom types."]},{"id":"goadvanced-003","courseId":"go-advanced","domain":"types-values","topic":"Size and alignment guarantees","prompt":"For a variable a of type [8]int64, unsafe.Alignof(a) equals the alignment of a single int64 value, not the total size of the array.","hint":"Think about where an array's alignment comes from: its length or its elements.","explain":"Alignment is the byte boundary that a value's address must respect. Composite types derive their alignment from their parts, so a larger total size does not automatically mean stricter alignment.","source":"https://go.dev/ref/spec#Size_and_alignment_guarantees","interaction":{"type":"true-false"},"options":[{"id":"a","text":"True","why":"The spec says an array's alignment is the same as the alignment of a variable of its element type."},{"id":"b","text":"False","whyNot":"The array's total size does not set its alignment; the alignment comes from the element type."}],"answer":"a","explanation":"For an array variable, unsafe.Alignof equals the alignment of its element type; the total size of the array does not change it.","concept":"For an array variable, unsafe.Alignof equals the alignment of its element type; the total size of the array does not change it.","rev":1,"updatedAt":"2026-10-23","kind":"scenario","takeaways":["Array alignment comes from the element type, not from the array's total length."]},{"id":"goadvanced-004","courseId":"go-advanced","domain":"types-values","topic":"Interface map keys","prompt":"A map has key type any. Its first store uses an int key, and its second store uses a slice as the key. What happens on the second store?","hint":"Ask when Go checks the key's comparability: at compile time or while the program runs.","explain":"A map key must support == and !=. When the key type is an interface, that check depends on the concrete value stored inside, which is known only while the program runs.","source":"https://go.dev/ref/spec#Map_types","interaction":{"type":"single"},"options":[{"id":"a","text":"It panics at run time, because the slice's dynamic type cannot be compared for map keys.","why":"With an interface key type, the comparison rules apply to the dynamic key value, and a slice fails them at run time."},{"id":"b","text":"It fails to compile, because slices can never be used as map keys.","whyNot":"The key type is an interface, so the compiler accepts the slice; the check happens while the program runs."},{"id":"c","text":"It stores the entry, since any accepts every value and keys compare by address.","whyNot":"Keys are not compared by address here; the value must be comparable, and a slice is not."},{"id":"d","text":"It stores the entry and compares slices element by element on lookup.","whyNot":"Go does not compare slices element by element as map keys; the store fails with a run-time panic."}],"answer":"a","explanation":"With an interface key type, comparison requires the dynamic key values to be comparable; using a non-comparable dynamic value causes a run-time panic.","concept":"With an interface key type, comparison requires the dynamic key values to be comparable; using a non-comparable dynamic value causes a run-time panic.","rev":1,"updatedAt":"2026-10-23","kind":"scenario","code":"m := map[any]int{}\nm[1] = 1\nm[[]int{2, 3}] = 2","takeaways":["Storing a slice as a key in an any-keyed map compiles but panics at run time."]},{"id":"goadvanced-005","courseId":"go-advanced","domain":"types-values","topic":"Union type sets","prompt":"The type MyInt is declared as shown. Which of these interface declarations is legal Go?","hint":"Check whether a ~ term names a type that is its own underlying type, and whether union terms overlap.","explain":"A type term ~T stands for every type whose underlying type is T. The terms of a union must not overlap, and a ~ term cannot name an interface.","source":"https://go.dev/ref/spec#General_interfaces","interaction":{"type":"single"},"options":[{"id":"a","text":"interface { ~float32 | ~float64 }","why":"The two terms have disjoint type sets, so this union is legal; it is the usual pattern for float constraints."},{"id":"b","text":"interface { ~int | MyInt }","whyNot":"The type sets overlap: ~int already includes MyInt, so this union is illegal."},{"id":"c","text":"interface { ~MyInt }","whyNot":"A ~T term needs T to be its own underlying type; MyInt's underlying type is int, so this is illegal."},{"id":"d","text":"interface { ~error }","whyNot":"error is an interface, and a ~T term cannot name an interface type."}],"answer":"a","explanation":"A ~T term must name its own underlying type and cannot be an interface; union terms must have disjoint type sets.","concept":"A ~T term must name its own underlying type and cannot be an interface; union terms must have disjoint type sets.","rev":1,"updatedAt":"2026-10-23","kind":"scenario","code":"type MyInt int","takeaways":["Overlapping union terms, such as ~int and a named int type, are a compile error."]}]