[{"id":"gointermediate-001","courseId":"go-intermediate","domain":"types-values","topic":"The iota constant","prompt":"A teammate asks which of these constant expressions is untyped, meaning its type comes only from the context where it is used. Which one is it?","hint":"Ask which of these gets its type only from context, not from a declaration or conversion.","explain":"Constants are either typed or untyped. A constant declaration or a conversion can attach an explicit type, while untyped constants take their type from the context where they are used.","source":"https://go.dev/ref/spec#Iota","interaction":{"type":"single"},"options":[{"id":"a","text":"iota, inside a const block","why":"The spec lists iota with true, false and literal constants as untyped."},{"id":"b","text":"const n int = 3","whyNot":"An explicit type in a constant declaration makes the constant typed, so n is an int."},{"id":"c","text":"int8(3)","whyNot":"A conversion gives a constant an explicit type, so the result is typed as int8."},{"id":"d","text":"const name string = \"go\"","whyNot":"The explicit string type in the declaration makes this constant typed."}],"answer":"a","explanation":"Literal constants, true, false and iota are untyped; a constant declaration or conversion gives a constant an explicit type.","concept":"Literal constants, true, false and iota are untyped; a constant declaration or conversion gives a constant an explicit type.","rev":1,"updatedAt":"2026-10-23","kind":"scenario","takeaways":["iota is an untyped integer constant, so it is not tied to any type unless the context gives one."]},{"id":"gointermediate-002","courseId":"go-intermediate","domain":"types-values","topic":"Type parameters and constraints","prompt":"Since Go 1.20, instantiating func Has[T comparable] with T set to any is a compile error, because an interface type can never satisfy comparable.","hint":"Check how a comparable type argument is judged against comparable in Go 1.20 and later.","explain":"A type argument must satisfy its parameter's constraint, a set of permitted types. The predeclared comparable constraint covers types that support == and !=, and interfaces get special treatment.","source":"https://go.dev/ref/spec#Type_parameter_declarations","interaction":{"type":"true-false"},"options":[{"id":"a","text":"True","whyNot":"Interfaces do satisfy comparable, though they are not strictly comparable; from Go 1.20 a comparable type argument like any is accepted."},{"id":"b","text":"False","why":"Since Go 1.20, a comparable type argument may satisfy the constraint, and any is comparable, so Has[any] compiles."}],"answer":"b","explanation":"Since Go 1.20, a strictly comparable constraint may also be satisfied by a comparable type argument; the spec lists any as satisfying comparable.","concept":"Since Go 1.20, a strictly comparable constraint may also be satisfied by a comparable type argument; the spec lists any as satisfying comparable.","rev":1,"updatedAt":"2026-10-23","kind":"scenario","takeaways":["From Go 1.20, comparable accepts interface type arguments like any, but == on such values can still panic at run time."]},{"id":"gointermediate-003","courseId":"go-intermediate","domain":"types-values","topic":"Type inference in generic calls","prompt":"A generic function is called without explicit type arguments, so the compiler has to infer them. Which TWO conditions must hold for type inference to succeed?","hint":"Think about which errors can stop inference, and what must be recorded for each type parameter.","explain":"Inference matches the argument types against the parameter types and records a type argument for each type parameter as it goes. Matching can fail when two requirements conflict.","source":"https://go.dev/ref/spec#Type_inference","interaction":{"type":"multiple","tellCount":true},"options":[{"id":"a","text":"No unification step fails.","why":"Inference succeeds only if every unification step succeeds, so one failed step means it fails."},{"id":"b","text":"The inference map has an entry for each type parameter.","why":"Every type parameter needs an inferred type argument; a missing entry means inference does not succeed."},{"id":"c","text":"The call spells out every type argument in square brackets.","whyNot":"Writing type arguments out is what inference lets you skip; it is not a condition for inference."},{"id":"d","text":"Every argument's type is identical to its parameter's type.","whyNot":"Unification can be loose and accept assignment-compatible types, so identical types are not required."},{"id":"e","text":"Each type parameter is constrained by comparable.","whyNot":"Constraints limit which types may be used; inference does not require any particular constraint."},{"id":"f","text":"The function's result type is one of its type parameters.","whyNot":"A result can have any type; inference works from the argument types and the parameter types."}],"answer":"ab","explanation":"Type inference succeeds if no unification step fails and the map has an entry for each type parameter.","concept":"Type inference succeeds if no unification step fails and the map has an entry for each type parameter.","rev":1,"updatedAt":"2026-10-23","kind":"scenario","takeaways":["Inference succeeds only when unification never fails and every type parameter ends up with an inferred type argument."]},{"id":"gointermediate-004","courseId":"go-intermediate","domain":"types-values","topic":"The comparable constraint","prompt":"A teammate writes func Keys[K any, V any](m map[K]V) []K and says it is fine, because K is only a type parameter. What does the compiler do with this declaration?","hint":"Think about what Go requires of every type used as a map key, and what any promises about K.","explain":"A type parameter's constraint limits which types it can stand for. The compiler also checks every type written in a signature, including the key type of a map.","source":"https://go.dev/doc/tutorial/generics","interaction":{"type":"single"},"options":[{"id":"a","text":"It rejects the code, because map keys must be comparable.","why":"Go requires map keys to be comparable, so the compiler rejects map[K]V unless K is constrained by comparable."},{"id":"b","text":"It accepts the code and checks the key type only when the function is called.","whyNot":"The compiler checks the map type where it is written, so the problem is reported at the declaration."},{"id":"c","text":"It accepts the code, because any allows every type, including slices.","whyNot":"any does allow slice types, but map keys need comparable types, and any does not promise that."},{"id":"d","text":"It accepts the code and only panics if a slice key is used.","whyNot":"A non-comparable key type for map[K]V is a compile-time error, not a run-time panic."}],"answer":"a","explanation":"Map key types must be comparable, so a generic map[K]V needs K constrained by comparable; without it, the compiler rejects the reference to map[K]V.","concept":"Map key types must be comparable, so a generic map[K]V needs K constrained by comparable; without it, the compiler rejects the reference to map[K]V.","rev":1,"updatedAt":"2026-10-23","kind":"scenario","takeaways":["Declare a generic map's key type parameter as comparable, or the compiler rejects map[K]V."]},{"id":"gointermediate-005","courseId":"go-intermediate","domain":"types-values","topic":"Generic type aliases","prompt":"On Go 1.24 with default settings, this declaration compiles without setting any GOEXPERIMENT flag.","hint":"Check what the Go 1.24 release notes say about the status of generic type aliases by default.","explain":"A type alias gives an existing type another name. Go 1.24 changed how generic aliases are supported, so the release notes describe the feature's status and its experiment setting.","source":"https://go.dev/doc/go1.24","interaction":{"type":"true-false"},"options":[{"id":"a","text":"True","why":"Go 1.24 fully supports generic type aliases; the feature is on unless GOEXPERIMENT=noaliastypeparams disables it."},{"id":"b","text":"False","whyNot":"The feature needs a GOEXPERIMENT flag to switch on in Go 1.24; without it, parameterized aliases are rejected."}],"answer":"a","explanation":"Go 1.24 fully supports generic type aliases, so a type alias may be parameterized like a defined type; GOEXPERIMENT=noaliastypeparams can disable it.","concept":"Go 1.24 fully supports generic type aliases, so a type alias may be parameterized like a defined type; GOEXPERIMENT=noaliastypeparams can disable it.","rev":1,"updatedAt":"2026-10-23","kind":"scenario","code":"type Set[T comparable] = map[T]struct{}","takeaways":["From Go 1.24, type aliases may take type parameters; GOEXPERIMENT=noaliastypeparams turns this off, for now."]}]