question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Dart targets do not build on Windows, "parent" defined inconsistently in RuleContext

See original GitHub issue

In trying to investigate https://github.com/antlr/antlr4/issues/3203 I ran into another problem.

I can’t seem to get Dart targets to compile on Windows, a problem with “parent”, which is inconsistently defined as a property declared in ParserRuleContext, a field in RuleContext, a property in ParseTree, a property in Tree.

I am using the latest Flutter package and Antlr4.9.2.

$ which dart
/c/Users/kenne/Downloads/flutter_windows_2.2.3-stable/flutter/bin/dart
$ dart --version
Dart SDK version: 2.13.4 (stable) (Wed Jun 23 13:08:41 2021 +0200) on "windows_x64"
$ make
java -jar c:/users/kenne/downloads/antlr-4.9.2-complete.jar -encoding utf-8 -Dlanguage=Dart  Abnf.g4
dart pub get
Resolving dependencies...
+ _fe_analyzer_shared 23.0.0
+ analyzer 2.0.0
+ antlr4 4.9.2
+ args 2.2.0
+ async 2.8.1
+ boolean_selector 2.1.0
+ charcode 1.3.1
+ cli_util 0.3.3
+ collection 1.15.0
+ convert 3.0.1
+ coverage 1.0.3
+ crypto 3.0.1
+ file 6.1.2
+ frontend_server_client 2.1.0
+ glob 2.0.1
+ http_multi_server 3.0.1
+ http_parser 4.0.0
+ io 1.0.3
+ js 0.6.3
+ logging 1.0.1
+ matcher 0.12.10
+ meta 1.7.0
+ mime 1.0.0
+ node_preamble 2.0.1
+ package_config 2.0.0
+ path 1.8.0
+ pedantic 1.11.1
+ pool 1.5.0
+ pub_semver 2.0.0
+ shelf 1.2.0
+ shelf_packages_handler 3.0.0
+ shelf_static 1.1.0
+ shelf_web_socket 1.0.1
+ source_map_stack_trace 2.1.0
+ source_maps 0.10.10
+ source_span 1.8.1
+ stack_trace 1.10.0
+ stream_channel 2.1.0
+ string_scanner 1.1.0
+ term_glyph 1.2.0
+ test 1.17.10
+ test_api 0.4.2
+ test_core 0.4.0
+ typed_data 1.3.0
+ vm_service 7.2.0
+ watcher 1.0.0
+ web_socket_channel 2.1.0
+ webkit_inspection_protocol 1.0.0
+ yaml 3.1.0
Changed 49 dependencies!
dart compile exe cli.dart
Info: Compiling without sound null safety
AbnfParser.dart:416:7: Error: The implementation of 'parent' in the non-abstract class 'RulelistContext' does not conform to its interface.
class RulelistContext extends ParserRuleContext {
      ^^^^^^^^^^^^^^^
../../../../../AppData/Local/Pub/Cache/hosted/pub.dartlang.org/antlr4-4.9.2/lib/src/rule_context.dart:66:16: Context: The return type of the method 'RuleContext.parent' is 'RuleContext', which does not match the return type, 'ParserRuleContext', of the overridden method, 'ParserRuleContext.parent'.
 - 'RuleContext' is from 'package:antlr4/src/rule_context.dart' ('../../../../../AppData/Local/Pub/Cache/hosted/pub.dartlang.org/antlr4-4.9.2/lib/src/rule_context.dart').
 - 'ParserRuleContext' is from 'package:antlr4/src/parser_rule_context.dart' ('../../../../../AppData/Local/Pub/Cache/hosted/pub.dartlang.org/antlr4-4.9.2/lib/src/parser_rule_context.dart').
Change to a subtype of 'ParserRuleContext'.
  RuleContext? parent;
	       ^
../../../../../AppData/Local/Pub/Cache/hosted/pub.dartlang.org/antlr4-4.9.2/lib/src/parser_rule_context.dart:132:26: Context: This is the overridden method ('parent').
  ParserRuleContext? get parent {
			 ^

Over on Ubuntu, this all works fine.

ken@llano:/mnt/c/Users/kenne/Documents/GitHub/i2248/abnf/Generated$ which dart
/usr/bin/dart
ken@llano:/mnt/c/Users/kenne/Documents/GitHub/i2248/abnf/Generated$ dart --version
Dart SDK version: 2.13.3 (stable) (Unknown timestamp) on "linux_x64"
ken@llano:/mnt/c/Users/kenne/Documents/GitHub/i2248/abnf/Generated$ make
java -jar /tmp/antlr-4.9.2-complete.jar -encoding utf-8 -Dlanguage=Dart  Abnf.g4
dart pub get
Resolving dependencies... (1.3s)
+ _fe_analyzer_shared 22.0.0 (23.0.0 available)
+ analyzer 1.7.2 (2.0.0 available)
+ antlr4 4.9.2
+ args 2.2.0
+ async 2.8.1
+ boolean_selector 2.1.0
+ charcode 1.3.1
+ cli_util 0.3.3
+ collection 1.15.0
+ convert 3.0.1
+ coverage 0.15.2 (1.0.3 available)
+ crypto 3.0.1
+ file 6.1.2
+ glob 2.0.1
+ http_multi_server 3.0.1
+ http_parser 4.0.0
+ io 1.0.3
+ js 0.6.3
+ logging 0.11.4 (1.0.1 available)
+ matcher 0.12.10
+ meta 1.7.0
+ mime 1.0.0
+ node_preamble 1.4.13 (2.0.1 available)
+ package_config 2.0.0
+ path 1.8.0
+ pedantic 1.11.1
+ pool 1.5.0
+ pub_semver 2.0.0
+ shelf 1.2.0
+ shelf_packages_handler 3.0.0
+ shelf_static 1.1.0
+ shelf_web_socket 1.0.1
+ source_map_stack_trace 2.1.0
+ source_maps 0.10.10
+ source_span 1.8.1
+ stack_trace 1.10.0
+ stream_channel 2.1.0
+ string_scanner 1.1.0
+ term_glyph 1.2.0
+ test 1.16.5 (1.17.10 available)
+ test_api 0.2.19 (0.4.2 available)
+ test_core 0.3.15 (0.4.0 available)
+ typed_data 1.3.0
+ vm_service 6.2.0 (7.2.0 available)
+ watcher 1.0.0
+ web_socket_channel 2.1.0
+ webkit_inspection_protocol 0.7.5 (1.0.0 available)
+ yaml 3.1.0
Downloading pedantic 1.11.1...
Downloading meta 1.7.0...
Downloading async 2.8.1...
Downloading shelf_static 1.1.0...
Downloading convert 3.0.1...
Downloading shelf 1.2.0...
Downloading io 1.0.3...
Downloading args 2.2.0...
Downloading file 6.1.2...
Downloading analyzer 1.7.2...
Downloading cli_util 0.3.3...
Changed 48 dependencies!
dart compile exe cli.dart
Info: Compiling without sound null safety
Generated: /mnt/c/Users/kenne/Documents/GitHub/i2248/abnf/Generated/cli.exe

flutter doctor didn’t report any problems other than “Some Android licenses not accepted. To resolve this, run: flutter doctor --android-licenses”.

First, I’m trying to determine if I am using the wrong version of Dart. But, the instructions for Dart targets says “From version 4.9.3 onwards antlr’s dart generated code is null sound safety compatible and sets the minimum dart sdk version to 2.12.0.”

It would be nice to mention the prereqs for the current version, 4.9.2 of Antlr.

Next, I looked at the code in the C# and Java runtimes. Those runtimes define consistently “parent” as a property, not a field. I changed the code locally to use a backing value for the property, and it seems to compile and run just fine.

$ diff -r . /c/Users/kenne/Documents/GitHub/antlr4-ubuntu/runtime/Dart/lib/src/
diff -r ./parser_rule_context.dart /c/Users/kenne/Documents/GitHub/antlr4-ubuntu/runtime/Dart/lib/src/parser_rule_context.dart
53c53
<       : super(parent_: parent, invokingState: invokingStateNumber);
---
>       : super(parent: parent, invokingState: invokingStateNumber);
diff -r ./rule_context.dart /c/Users/kenne/Documents/GitHub/antlr4-ubuntu/runtime/Dart/lib/src/rule_context.dart
64,66d63
<
<   RuleContext? parent_;
<
69,76c66
<   RuleContext? get parent {
<     return parent_;
<   }
<
<   @override
<   set parent(RuleContext? v) {
<     parent_ = v;
<   }
---
>   RuleContext? parent;
83c73
<   RuleContext({this.parent_, int? invokingState})
---
>   RuleContext({this.parent, int? invokingState})

“parent” is defined inconsistently in RuleContext. It should be implemented with a backing field. See the diffs.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:5 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
kaby76commented, Aug 8, 2021

@lingyv-li You are likely best up to date on the Dart target. Please review. Thanks, Ken

0reactions
lingyv-licommented, Aug 9, 2021

I think you forgot to run dart pub get under antlr4/runtime/Dart before using dart analyze

Read more comments on GitHub >

github_iconTop Results From Across the Web

ParserRuleContext class - antlr4 library - Dart API - Pub.dev
A rule invocation record for parsing. Contains all of the information about the current rule not stored in the RuleContext. It handles parse...
Read more >
eslint-config-eslint | Yarn - Package Manager
Contains the ESLint configuration used for projects maintained by the ESLint team. Installation. You can install ESLint using npm: npm install eslint --save-dev....
Read more >
USAA - Board of Governors of the Federal Reserve System
USAA is a holding company for a diversified financial services group of companies and is itself a personal lines property and casualty insurance ......
Read more >
Old Release Notes | PMD Source Code Analyzer
The new attribute disabled should be used instead for defining whether a rule test should be skipped or not. The attributes reinitializeRule and...
Read more >
Vol. 83 Monday, No. 5 January 8, 2018 Pages 705–970
The Board also published inconsistent ... institution that is not a savings and loan ... regulatory action as that term is defined.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found