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

Phase 2 of Typing Improvements #827

Merged
merged 14 commits into from
Jul 17, 2023
Merged

Phase 2 of Typing Improvements #827

merged 14 commits into from
Jul 17, 2023

Conversation

markwpearce
Copy link
Collaborator

@markwpearce markwpearce commented Jun 19, 2023

A second phase of type improvements for Brighterscript

Tasks

  • BinaryExpressions and UnaryExpressions should be able to infer resultant types (eg. Integer * Integer => Integer, String + String => String, etc.)

  • Change Hover & Completion to use SymbolTable instead of variableDeclarations/callables
    This will complete the refactor to move away from using these lookup tables to unify how a symbol can be discovered/known. When this is done, the concept of VariableDeclarations can be removed from the code.

  • Validate function calls for argument type validity

    Function argument equality

    sub main()
        printMessage(1)
        '            ~ Argument of type 'number' is not assignable to parameter of type 'string'
    end sub
    function printMessage(message as string)
        print message
    end function

Phase 3

  • Validate assignment expressions for type validity

    AssignmentStatement type equality

    sub main()
        name = "bob"
        name = 1
    end sub
    '      ~ type 'Integer' cannot be assigned to type 'String'
  • Add ComponentType that are generated from XML or future Component creation. Members (and member types) could be inferred from the component's fields

  • CreateObject() should infer correct type (using data scraped from Roku SceneGraph docs for built in types, or from known components)

  • Update ArrayType to allow indexedGet, etc. to infer type. Allow code & validation like:

  function sumArray(numbers as integer[]) as integer
       sum = 0
       for each num in numbers
           sum = sum + num ' num is known to be an integer
       end for
       return sum
   end function
   
   sub addName(nameList as string[])
        nameList.push(3.14) ' validation error --- nameList.push expects string
    end sub

   ```

@markwpearce markwpearce changed the base branch from master to release-0.66.0 June 19, 2023 19:28
@TwitchBronBron TwitchBronBron marked this pull request as ready for review July 17, 2023 16:56
@TwitchBronBron TwitchBronBron merged commit a6a7b51 into release-0.66.0 Jul 17, 2023
5 checks passed
@TwitchBronBron TwitchBronBron deleted the typing-phase2 branch July 17, 2023 18:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants