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

Handle implicit type conversion when calling functions #298

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Commits on Apr 5, 2024

  1. Test cases to reproduce type errors

    These tests will fail and generate the following:
    ```
    <========= Request finished
    Request Incoming =========>
    [regsub] Argument 1 expects STRING type but BACKEND provided
    <========= Request finished
    Request Incoming =========>
    [regsub] Argument 1 expects STRING type but TIME provided
    <========= Request finished
    ```
    MasonM committed Apr 5, 2024
    Configuration menu
    Copy the full SHA
    335381e View commit details
    Browse the repository at this point in the history
  2. Handle implicit type conversion when calling functions

    This fixes errors like `[regsub] Argument 1 expects STRING type but
    BACKEND provided` when calling builtin functions and passing a
    non-string for a string argument. Fastly handles that by implicitly converting the
    argument to a string:
    > These types all have implicit conversions to strings, such that their values may be used in contexts where a STRING value is necessary.
    https://www.fastly.com/documentation/reference/vcl/types/
    
    I wasn't sure the cleanist way of implementing. Originally, I was
    thinking of doing this conversion in `ProcessFunctionCallExpression()` and
    `ProcessFunctionCallStatement()` (the two places that call functions)
    like we're already doing for the `IsIdentArgument()` check, but it
    needs to know the argument types for every function to do that, which
    means encoding that information in the `Function` struct.
    MasonM committed Apr 5, 2024
    Configuration menu
    Copy the full SHA
    bb1f26f View commit details
    Browse the repository at this point in the history