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

Parser exception when tearing off a property of a thing via a cascade #46635

Closed
srawlins opened this issue Jul 15, 2021 · 2 comments
Closed

Parser exception when tearing off a property of a thing via a cascade #46635

srawlins opened this issue Jul 15, 2021 · 2 comments
Assignees
Labels
area-front-end Use area-front-end for front end / CFE / kernel format related issues. front-end-fasta type-bug Incorrect behavior (everything from a crash to more subtle misbehavior)

Comments

@srawlins
Copy link
Member

This code throws an exception, with constructor tearoffs enabled:

class A {
  void foo<T>(T a) {}
}

bar(A a) {
  a..foo<int>;
}

I think it is valid, but it should not throw, even if it is invalid. Stack trace when run as an analyzer test case:

'package:_fe_analyzer_shared/src/parser/parser_impl.dart': Failed assertion: line 5163 pos 16: 'optional('(', next)': is not true.                                                            
  #0      _AssertionError._doThrowNew (dart:core-patch/errors_patch.dart:46:39)                                                                                                                 
  #1      _AssertionError._throwNew (dart:core-patch/errors_patch.dart:36:5)                                                                                                                    
  #2      Parser.parseCascadeExpression (package:_fe_analyzer_shared/src/parser/parser_impl.dart:5163:16)                                                                                       
  #3      Parser._parsePrecedenceExpressionLoop (package:_fe_analyzer_shared/src/parser/parser_impl.dart:4881:19)                                                                               
  #4      Parser.parsePrecedenceExpression (package:_fe_analyzer_shared/src/parser/parser_impl.dart:4857:12)                                                                                    
  #5      Parser.parseExpression (package:_fe_analyzer_shared/src/parser/parser_impl.dart:4780:13)                                                                                              
  #6      Parser.parseExpressionStatement (package:_fe_analyzer_shared/src/parser/parser_impl.dart:4745:13)                                                                                     
  #7      Parser.parseExpressionStatementOrDeclarationAfterModifiers (package:_fe_analyzer_shared/src/parser/parser_impl.dart:6635:16)                                                          
  #8      Parser.parseStatementX (package:_fe_analyzer_shared/src/parser/parser_impl.dart:4541:14)                                                                                              
  #9      Parser.parseStatement (package:_fe_analyzer_shared/src/parser/parser_impl.dart:4531:20)                                                                                               
  #10     Parser.parseFunctionBody (package:_fe_analyzer_shared/src/parser/parser_impl.dart:4436:15)                                                                                            
  #11     Parser.parseTopLevelMethod (package:_fe_analyzer_shared/src/parser/parser_impl.dart:2950:13)                                                                                          
  #12     Parser.parseTopLevelMemberImpl (package:_fe_analyzer_shared/src/parser/parser_impl.dart:2729:14)                                                                                      
  #13     Parser.parseTopLevelDeclarationImpl (package:_fe_analyzer_shared/src/parser/parser_impl.dart:502:14)                                                                                  
  #14     Parser.parseUnit (package:_fe_analyzer_shared/src/parser/parser_impl.dart:357:15)                                                                                                     
  #15     Parser.parseCompilationUnit2 (package:analyzer/src/generated/parser.dart:195:32)                                                                                                      
  #16     Parser.parseCompilationUnit (package:analyzer/src/generated/parser.dart:191:12)                                                                                                       
  #17     FileState._parse (package:analyzer/src/dart/analysis/file_state.dart:601:23)                                                                                                          
  #18     FileState.parse (package:analyzer/src/dart/analysis/file_state.dart:404:14)                                                                                                           
  #19     FileState._getUnlinkedBytes (package:analyzer/src/dart/analysis/file_state.dart:546:16)                                                                                               
  #20     FileState.refresh (package:analyzer/src/dart/analysis/file_state.dart:451:17)                                                                                                         
  #21     FileSystemState.getFileForPath (package:analyzer/src/dart/analysis/file_state.dart:857:12)                                                                                            
  #22     AnalysisDriver._computeAnalysisResult (package:analyzer/src/dart/analysis/driver.dart:1323:31)                                                                                        
  #23     AnalysisDriver.performWork (package:analyzer/src/dart/analysis/driver.dart:992:22)                                                                                                    
  #24     AnalysisDriverScheduler._run (package:analyzer/src/dart/analysis/driver.dart:2105:24)                                                                                                 
  <asynchronous suspension>
@srawlins srawlins added type-bug Incorrect behavior (everything from a crash to more subtle misbehavior) front-end-fasta area-front-end Use area-front-end for front end / CFE / kernel format related issues. labels Jul 15, 2021
@srawlins
Copy link
Member Author

cc @stereotype441

@stereotype441 stereotype441 self-assigned this Jul 15, 2021
@eernstg
Copy link
Member

eernstg commented Jul 16, 2021

The feature specification for 'constructor-tearoffs' does not cover cascades, but the spec_parser grammar Dart.g was extended with support for this feature in https://dart-review.googlesource.com/c/sdk/+/197161. It makes <typeArguments> a selector, and that enables a..foo<int>.

Of course, it's not that useful because it computes a value in a computation that can't have side-effects, and then the result is discarded. So we'll probably never have it anywhere outside language tests, and it might even be targeted by a lint. ;-)

Cf. dart-lang/language#1746.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-front-end Use area-front-end for front end / CFE / kernel format related issues. front-end-fasta type-bug Incorrect behavior (everything from a crash to more subtle misbehavior)
Projects
None yet
Development

No branches or pull requests

3 participants