Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simplify check for Google::Protobuf::Map type - redux #1541

Merged
merged 3 commits into from
Jun 23, 2023

Commits on Jun 23, 2023

  1. Add failing tests

    paracycle committed Jun 23, 2023
    Configuration menu
    Copy the full SHA
    0d1ec21 View commit details
    Browse the repository at this point in the history
  2. If a message class does not have a name, map it to T.untyped

    If the `msgclass` of a subtype is not assigned to a constant, then its `#name` method would return `nil` and the compiler would return it as the type name of the descriptor. Not only does this break the contract of the `type_of` method defined by its signature which promises to always return a `String` instance, but it also leads to us generating broken RBI files, since these `nil` values serialize to empty strings.
    
     This commit fixes this by mapping the message class to `T.untyped` if it does not have a name.
    paracycle committed Jun 23, 2023
    Configuration menu
    Copy the full SHA
    0dabeda View commit details
    Browse the repository at this point in the history
  3. Detect map types by trying to assign a hash value for the field

    The realization is that you can't assign an array type to `Map` fields and that you can't assign a hash type to `Repeated` fields. So we can use that to detect the type of the field.
    
    We try to instantiate a new instance of the constant type, setting the value of the current descriptor field to an empty hash. If the type is `Map`, then it will succeed. If it's `Repeated`, it will fail.
    paracycle committed Jun 23, 2023
    Configuration menu
    Copy the full SHA
    011b826 View commit details
    Browse the repository at this point in the history