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

Generated accessors for optional items should allow undefined #265

Closed
sharwell opened this issue Jan 4, 2017 · 1 comment
Closed

Generated accessors for optional items should allow undefined #265

sharwell opened this issue Jan 4, 2017 · 1 comment
Assignees
Milestone

Comments

@sharwell
Copy link
Member

sharwell commented Jan 4, 2017

As described in #261, the generated accessor AContext.b() has the wrong return type for the following grammar:

grammar Test;

a : b? c d* d+ ;
b : ID;
c : ID;
d : ID;
e : ID;

Expected signatures:

export class AContext extends ParserRuleContext {
  b(): BContext | undefined;
  c(): CContext;
  d(): DContext[];
  d(i: number): DContext;
  e(): EContext[];
  e(i: number): EContext;
  // ...
}

Actual signatures:

export class AContext extends ParserRuleContext {
  b(): BContext;
  c(): CContext;
  d(): DContext[];
  d(i: number): DContext;
  e(): EContext[];
  e(i: number): EContext;
  // ...
}

Difference we want to see (actual → expected)

 export class AContext extends ParserRuleContext {
-  b(): BContext;
+  b(): BContext | undefined;
   c(): CContext;
   d(): DContext[];
   d(i: number): DContext;
   e(): EContext[];
   e(i: number): EContext;
   // ...
 }

/cc @mike-lischke

@sharwell
Copy link
Member Author

sharwell commented Jan 4, 2017

📝 Currently blocked on tunnelvisionlabs/antlr4#15.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant