Skip to content

Bug in optional chaining typechecker #854

Closed

Description

@antonmedv

Example from playground:

user.Profile?.Address ?? "Unknown address"
user:
  Id: 1
  Name: John Doe
  Group: admin

Activity

  1. added this to the v1.17.7 milestone on Oct 20, 2025
  2. ehabterra commented on Dec 7, 2025

    @ehabterra

    Hey @antonmedv,

    I'd like to contribute to this project and this issue looks like a good fit. I'm still learning the codebase, so please bear with me.

    I've been investigating the issue. For the expression user.Profile?.Address ?? "Unknown address", when Profile doesn't exist on the User struct, the type checker throws a "has no field" error during type checking.

    Is this the issue we need to fix?

    I also have a question about scope: should we also handle cases like:

    user.Profiles[0]?.Address ?? "Unknown address"

    I've made some changes to the checker, but I'm encountering an error from runtime.go file: "cannot fetch Profile from expr_test.User (1:6)". I'm still debugging this and would appreciate any guidance on the expected behavior.

    Thanks!

  3. antonmedv commented on Dec 8, 2025

    @antonmedv
    MemberAuthor

    Hey @ehabterra

    Yes, i think this is the issue. Now sure what is the culprit here. Need to investigate.

  4. ehabterra commented on Dec 8, 2025

    @ehabterra

    This should be resolved now. Please let me know if I missed anything or if there's anything I should address. #874

  5. antonmedv commented on Dec 14, 2025

    @antonmedv
    MemberAuthor

    Actually, behavior here is correct. Playground is using types.Map and this is proper behavior.

  6. added a commit that references this issue on Dec 14, 2025
    f493d7d
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions