Skip to content

Bug: json.decode() returns internal 'any' type that users cannot use #947

@SchoolyB

Description

@SchoolyB

Description

json.decode() without a type argument returns (any, error), but any is an internal-only type that users cannot declare or work with.

temp result, err = json.decode(jsonString)
// result has type 'any' - but what can the user do with it?

The user cannot:

  • Declare a variable as any: temp x any = ... is not allowed
  • Pass it to a function expecting a concrete type
  • Use it meaningfully without casting

Affected Functions

From pkg/typechecker/typechecker.go:4947-4956:

case "decode":
    if len(args) >= 2 {
        if label, ok := args[1].(*ast.Label); ok {
            return []string{label.Value, "error"}
        }
    }
    return []string{"any", "error"}  // ← Problem
case "parse", "parse_file":
    return []string{"any", "error"}  // ← Same problem

Expected Behavior

Either:

  1. Require a type argument: json.decode(text, MyType) - no untyped version
  2. Return a usable dynamic type that users can work with
  3. Document a pattern for working with untyped JSON (if one exists)

Current Workaround

Always provide a type argument:

temp result, err = json.decode(jsonString, MyStruct)

But if users don't know the type at compile time, they're stuck.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingstdlibGeneral standard library issuestypecheckerRelated to type checking and validation

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions