rokucommunity / rokucommunity/brighterscript
Implement primitive type narrowing for global functions
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 208
- Forks
- 68
- Avg merge
- 8h 39m
- Merged PRs (30d)
- 39
Description
Add some very primitive type narrowing for global functions.
General syntax:
if type(doSomething) = "roFunction" then
doSomething()
end if
You must wrap your function with an if statement that includes one or both of these conditions, but must contain no other conditions. Like this:
if type(theThing) = "roFunction"
if type(theThing) = "Function"
if type(theThing) = "roFunction" or type(theThing) = "Function"
The order may also be swapped. Like this:
if type(theThing) = "roFunction"
if "roFunction" = type(theThing)
The way we will implement this in v0 is:
- when we're about to add the
cannot find namediagnostic, we will walk up the ast tree looking at every if statement. if it matches one of the syntaxes above, then we will NOT add the diagnostic.
NOTE: this is NOT a broad type guard implementation, and is exclusively for global functions
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start at the code path that adds the "cannot find name" diagnostic and inspect the AST traversal around enclosing if statements. Implement only the listed type(...) condition forms for global functions, then verify that matching conditions suppress the diagnostic while other conditions still report it.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- compilers
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100