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

[tool_crash] _CastError: (#0 LocalizationsGenerator._generateMethod.generateHelperMethods (package:flutter_tools/src/localizations/gen_l10n.dart:1214:54)) #116459

Closed
rares45 opened this issue Dec 3, 2022 · 8 comments · Fixed by #116622 or #116625
Assignees
Labels
a: internationalization Supporting other languages or locales. (aka i18n) c: crash Stack traces logged to the console P2 Important issues not at the top of the work list r: fixed Issue is closed as already fixed in a newer version tool Affects the "flutter" command-line tool. See also t: labels.

Comments

@rares45
Copy link

rares45 commented Dec 3, 2022

Command

flutter gen-l10n --verbose

Steps to Reproduce

  1. Upgrade flutter from stable to beta
  2. Run flutter gen-l10n --verbose

Logs

_CastError: (#0 LocalizationsGenerator._generateMethod.generateHelperMethods (package:flutter_tools/src/localizations/gen_l10n.dart:1214:54))

#0      LocalizationsGenerator._generateMethod.generateHelperMethods (package:flutter_tools/src/localizations/gen_l10n.dart:1214:54)
#1      LocalizationsGenerator._generateMethod.generateHelperMethods.<anonymous closure> (package:flutter_tools/src/localizations/gen_l10n.dart:1116:41)
#2      MappedListIterable.elementAt (dart:_internal/iterable.dart:414:31)
#3      ListIterator.moveNext (dart:_internal/iterable.dart:343:26)
#4      new _GrowableList._ofEfficientLengthIterable (dart:core-patch/growable_array.dart:189:27)
#5      new _GrowableList.of (dart:core-patch/growable_array.dart:150:28)
#6      new List.of (dart:core-patch/array_patch.dart:52:28)
#7      ListIterable.toList (dart:_internal/iterable.dart:214:7)
#8      LocalizationsGenerator._generateMethod.generateHelperMethods (package:flutter_tools/src/localizations/gen_l10n.dart:1119:14)
#9      LocalizationsGenerator._generateMethod (package:flutter_tools/src/localizations/gen_l10n.dart:1280:5)
#10     LocalizationsGenerator._generateBaseClassFile.<anonymous closure> (package:flutter_tools/src/localizations/gen_l10n.dart:905:14)
#11     MappedIterator.moveNext (dart:_internal/iterable.dart:392:20)
#12     Iterable.join (dart:core/iterable.dart:431:23)
#13     LocalizationsGenerator._generateBaseClassFile (package:flutter_tools/src/localizations/gen_l10n.dart:919:41)
#14     LocalizationsGenerator._generateCode (package:flutter_tools/src/localizations/gen_l10n.dart:1015:46)
#15     LocalizationsGenerator.writeOutputFiles (package:flutter_tools/src/localizations/gen_l10n.dart:1286:47)
#16     generateLocalizations (package:flutter_tools/src/localizations/gen_l10n.dart:71:9)
#17     GenerateLocalizationsCommand.runCommand (package:flutter_tools/src/commands/generate_localizations.dart:228:24)
#18     FlutterCommand.verifyThenRunCommand (package:flutter_tools/src/runner/flutter_command.dart:1423:12)
<asynchronous suspension>
#19     FlutterCommand.run.<anonymous closure> (package:flutter_tools/src/runner/flutter_command.dart:1257:27)
<asynchronous suspension>
#20     AppContext.run.<anonymous closure> (package:flutter_tools/src/base/context.dart:150:19)
<asynchronous suspension>
#21     CommandRunner.runCommand (package:args/command_runner.dart:209:13)
[✓] Flutter (Channel beta, 3.6.0-0.1.pre, on Ubuntu 22.10 5.19.0-26-generic, locale en_GB.UTF-8)
    • Flutter version 3.6.0-0.1.pre on channel beta at /home/rares/.apps/flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 75927305ff (2 weeks ago), 2022-11-17 05:52:50 +0530
    • Engine revision b754eabc98
    • Dart version 2.19.0 (build 2.19.0-374.1.beta)
    • DevTools version 2.19.0

[✓] Android toolchain - develop for Android devices (Android SDK version 33.0.1)
    • Android SDK at /home/rares/.apps/android-sdk/
    • Platform android-33, build-tools 33.0.1
    • Java binary at: /home/rares/.apps/jetbrains-toolbox/apps/AndroidStudio/ch-0/213.7172.25.2113.9123335/jre/bin/java
    • Java version OpenJDK Runtime Environment (build 11.0.13+0-b1751.21-8125866)
    • All Android licenses accepted.

[✓] Chrome - develop for the web
    • Chrome at google-chrome

[✓] Linux toolchain - develop for Linux desktop
    • Ubuntu clang version 15.0.2-1
    • cmake version 3.24.2
    • ninja version 1.11.0
    • pkg-config version 0.29.2

[✓] Android Studio (version 2021.3)
    • Android Studio at /home/rares/.apps/jetbrains-toolbox/apps/AndroidStudio/ch-0/213.7172.25.2113.9123335
    • Flutter plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/6351-dart
    • Java version OpenJDK Runtime Environment (build 11.0.13+0-b1751.21-8125866)

[✓] VS Code (version 1.73.1)
    • VS Code at /usr/share/code
    • Flutter extension version 3.54.0

[✓] Connected device (2 available)
    • Linux (desktop) • linux  • linux-x64      • Ubuntu 22.10 5.19.0-26-generic
    • Chrome (web)    • chrome • web-javascript • Google Chrome 108.0.5359.94

[✓] HTTP Host Availability
    • All required HTTP hosts are available

• No issues found!

Flutter Application Metadata

Type: app
Version: 0.0.1+1
Material: true
Android X: false
Module: false
Plugin: false
Android package: null
iOS bundle identifier: null
Creation channel: beta
Creation framework version: d6260f1

Plugins

dynamic_color-1.5.4
flutter_native_splash-2.2.16
mobile_scanner-2.1.0
package_info_plus-3.0.2

@rares45
Copy link
Author

rares45 commented Dec 3, 2022

Here is my l10n.yaml:

arb-dir: lib/l10n
template-arb-file: lw_en.arb
output-localization-file: lw_localizations.dart
output-class: LWLocalizations
nullable-getter: false

@darshankawar darshankawar added the in triage Presently being triaged by the triage team label Dec 5, 2022
@darshankawar
Copy link
Member

I am unable to replicate the issue based on details provided. Keeping it open and labeling for team's attention.

@darshankawar darshankawar added c: crash Stack traces logged to the console tool Affects the "flutter" command-line tool. See also t: labels. a: internationalization Supporting other languages or locales. (aka i18n) and removed in triage Presently being triaged by the triage team labels Dec 5, 2022
@darshankawar
Copy link
Member

/cc @christopherfujino

@rares45
Copy link
Author

rares45 commented Dec 5, 2022

After some debugging it seems removing these lines from my arb is fixing the crash:

"profileType": "{level, plural, =0{Novice} =1{Not bad} =2{TODO} =3{Gamer} other{True gamer}}",
"@profileType": {
  "placeholders": {
    "level": {
      "description": "The level. Starts from 0",
      "format": "decimalPattern",
      "type": "num"
    }
  }
},

@christopherfujino christopherfujino added the P2 Important issues not at the top of the work list label Dec 6, 2022
@christopherfujino
Copy link
Member

@thkim1011 it seems like this no longer affects the master channel with the new parser, is that correct?

@thkim1011
Copy link
Contributor

I think this may be a bug. Technically, the =3 or three case is not valid syntax, but I forgot to handle this case. I'll make a PR with a fix.

@thkim1011
Copy link
Contributor

thkim1011 commented Dec 6, 2022

@rares45 you might want to consider using a select case instead as follows:

"profileType": "{level, select, level0{Novice} level1{Not bad} level2{TODO} level3{Gamer} other{True gamer}}",
"@profileType": {
  "placeholders": {
    "level": {
      "description": "The level. Starts from 0",
      "format": "decimalPattern",
      "type": "String"
    }
  }
},

and use the string with LWLocalizations.of(context).profileType('level$level').

Currently, it will throw a syntax error if numbers are used for select cases instead of alphanumeric strings, but I'm working on a fix for this as well.

@github-actions
Copy link

github-actions bot commented Mar 5, 2023

This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of flutter doctor -v and a minimal reproduction of the issue.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 5, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
a: internationalization Supporting other languages or locales. (aka i18n) c: crash Stack traces logged to the console P2 Important issues not at the top of the work list r: fixed Issue is closed as already fixed in a newer version tool Affects the "flutter" command-line tool. See also t: labels.
Projects
None yet
4 participants