-
Notifications
You must be signed in to change notification settings - Fork 35
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
Adding a validation pass to check types, field IDs and Identifiers #70
Conversation
* validate that types are being assigned properly * validate all identifiers can be resolved * validate no duplicate field IDs * validate correct enum usage
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.
Looks like a 0-line file debugger.ts
got committed. Also made a few inline comments about some things I saw. Haven't run the test suite locally - I'd love to get this on CI.
case SyntaxType.DoubleConstant: | ||
return createLiteral(node.value) | ||
return ts.createLiteral(node.value) | ||
|
||
case SyntaxType.ConstList: |
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.
The parser should differentiate between ConstList and ConstSet for the future.
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.
The IDL only defines ConstList. It's more context awareness than I would like to have the parser add a ConstSet. It should be rendering a Set here though, don't know why I missed that/how I'm not testing for it. Will fix.
]) | ||
}) | ||
|
||
return createNew( | ||
return ts.createNew( |
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.
Random thought: does Scrooge make this improvement to Maps? If not, this probably needs to generate a plain object until Maps and Sets are used consistently and all normalization applied.
This new Map
change was my improvement/fix and required more changed within the codegen output.
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.
Yeah, scrooge uses Map instead of object literals.
src/app/resolver.ts
Outdated
@@ -291,12 +320,15 @@ function createResolver(thrift: ThriftDocument, includes: IIncludeMap): IResolve | |||
return false | |||
} | |||
|
|||
/** | |||
* | |||
* @param name |
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.
Mistakenly inserted?
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.
Yup
src/app/validator/index.ts
Outdated
type: SyntaxType.ServiceDefinition, | ||
name: statement.name, | ||
functions: validateFunctions(statement.functions), | ||
extends: statement.extends, |
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 extends should be validated also. You can extend an included service.
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.
Good catch.
src/app/validator/index.ts
Outdated
if (fieldID === null) { | ||
return { | ||
type: SyntaxType.FieldID, | ||
value: (--generatedFieldID), |
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.
generatedFieldID
should be pushed onto usedFieldIDs
after it's used.
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 should be checking that the user supplied id is not negative right. Negative IDs are reserved for generation if I remember correctly?
src/app/validator/index.ts
Outdated
} | ||
|
||
function validateFields(fields: Array<FieldDefinition>): Array<FieldDefinition> { | ||
generatedFieldID = 0 |
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 seems fine as long as Thrift continues to not support nested struct definition.
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.
Yeah, the scope of generatedFieldID and usedFieldIDs is probably too broad. I'll fix that.
src/app/validator/index.ts
Outdated
return { | ||
type: SyntaxType.FunctionDefinition, | ||
name: func.name, | ||
oneway: func.oneway, |
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 being validated with void
type?
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.
The parser is checking for oneway == void now. I'm thinking about getting rid of that check in the parser and moving all of that sort of validation here. Thoughts?
* Should check extends identifier to ensure it is referencing a service * Should check that user created field IDs are non-negative * Get rid of the nasty scoping around generated field IDs * Should be rendering Sets where sets have default values (was using array)
src/app/render/struct/read.ts
Outdated
@@ -347,6 +347,9 @@ export function readValueForIdentifier( | |||
case SyntaxType.ConstDefinition: | |||
throw new TypeError(`Identifier ${id.definition.name.value} is a value being used as a type`) | |||
|
|||
case SyntaxType.ServiceDefinition: | |||
throw new TypeError(`Service ${id.definition.name.value} is begin used as a type`) |
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.
begin -> beign
src/app/render/struct/write.ts
Outdated
@@ -146,6 +146,9 @@ function writeValueForIdentifier( | |||
case SyntaxType.ConstDefinition: | |||
throw new TypeError(`Identifier ${id.definition.name.value} is a value being used as a type`) | |||
|
|||
case SyntaxType.ServiceDefinition: | |||
throw new TypeError(`Service ${id.definition.name.value} is begin used as a type`) |
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.
begin -> being
src/app/render/types.ts
Outdated
@@ -181,6 +181,9 @@ function thriftAccessForIdentifier(id: IIdentifierType, identifiers: IIdentifier | |||
case SyntaxType.ConstDefinition: | |||
throw new TypeError(`Identifier ${id.definition.name.value} is a value being used as a type`) | |||
|
|||
case SyntaxType.ServiceDefinition: | |||
throw new TypeError(`Service ${id.definition.name.value} is begin used as a type`) |
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.
begin -> being
As part of this I also fix initializing i64 fields to numbers, now Int64.