-
Notifications
You must be signed in to change notification settings - Fork 56
Intersection Type #1603
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
base: v1
Are you sure you want to change the base?
Intersection Type #1603
Conversation
…n and using union type in BRS mode
| expressionsWithOperator.push({ expression: expr }); | ||
|
|
||
| // handle expressions with order of operations - first "and", then "or" | ||
| const combineExpressions = (opToken: TokenKind) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Potentially there is a better way of doing this...
This algorithm just gets a list of <type> <operator?>, and then first loops through it to combine all ands into binary expressions, then again to combine all ors
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think in practice, this is fine, though
| if (this.match(TokenKind.LeftCurlyBrace)) { | ||
| expr = this.inlineInterface(); | ||
| } else if (this.match(TokenKind.LeftParen)) { | ||
| let left = this.previous(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This type expression is a GroupingExpression, eg. (integer or float)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would this github comment be better served as an actual in-code comment?
|
Accomplishes #1330 |
|
Hey there! I just built a new temporary npm package based on 5e648aa. You can download it here or install it by running the following command: npm install https://github.com/rokucommunity/brighterscript/releases/download/v0.0.0-packages/brighterscript-1.0.0-alpha.49-intersection-type.20260120154200.tgz |
TwitchBronBron
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just a few small things, but overall this looks great!
| export function isParamTypeFromValueReferenceType(value: any): value is ParamTypeFromValueReferenceType { | ||
| return value?.__reflection?.name === 'ParamTypeFromValueReferenceType'; | ||
| } | ||
| export function isIntersectionWithDefaultDynamicReferenceType(value: any): value is IntersectionWithDefaultDynamicReferenceType { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This name is...a lot. 😅 It might be worth adding a comment about what this specific function actually accomplishes. I don't really understand it, even though I can read all the words in its name.
|
|
||
| export function isInheritableType(target): target is InheritableType { | ||
| return isClassType(target) || isCallFuncableType(target) || isComplexTypeOf(target, isInheritableType); | ||
| return isClassType(target) || isInterfaceType(target) || isComponentType(target); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this a bug? It used to use isComplexType but now is isComponentType. I'm not entirely sure what isInheritableType is used for, but does it allow you to do something like class Alpha extends roSGNodeGroup? (maybe all of this is fine and I'm overthinking it).
Was it actually supposed to be isCompoundType?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It was a bug before.
isInheritableType() is any type that can be extended with extends
| } | ||
| } | ||
| if (this.checkAny(TokenKind.And, TokenKind.Or)) { | ||
| this.warnIfNotBrighterScriptMode('custom types'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a better name than custom types? I know this is configurable, but feels like it would better to say something like intersection or union?
| if (this.match(TokenKind.LeftCurlyBrace)) { | ||
| expr = this.inlineInterface(); | ||
| } else if (this.match(TokenKind.LeftParen)) { | ||
| let left = this.previous(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would this github comment be better served as an actual in-code comment?
|
Hey there! I just built a new temporary npm package based on d277935. You can download it here or install it by running the following command: npm install https://github.com/rokucommunity/brighterscript/releases/download/v0.0.0-packages/brighterscript-1.0.0-alpha.49-intersection-type.20260120174746.tgz |
Co-authored-by: Bronley Plumb <bronley@gmail.com>
|
Hey there! I just built a new temporary npm package based on 92a7755. You can download it here or install it by running the following command: npm install https://github.com/rokucommunity/brighterscript/releases/download/v0.0.0-packages/brighterscript-1.0.0-alpha.49-intersection-type.20260120180333.tgz |
Adds
IntersectionTypemodelled after TypeScript's intersection typesIntersectionType<type> and <type>(type1 or type2) and (type3 or type4))type foo = myType1 or myType2 and myType3 or myType4=>myType1 or (myType2 and myType3) or myType4type MyKlassAA = MyKlass and roAssociativeArrayworks properly