You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The new feature of Multiple Generations for the Same Class #124 introduces an issue when the strict-casts language rule is enabled in the analysis_options.yaml. This causes a type error when generating code using build_runner.
Steps to Reproduce
Create app_env_fields.dart:
abstract interface class AppEnvFields {
abstract final String apiUrl;
}
Create envs.env.dart:
import 'package:envied/envied.dart';
import 'app_env_fields.dart';
part `'envs.env.g.dart'`;
@Envied(path: '.env.production', name: 'Prod')
@Envied(path: '.env.staging', name: 'Staging')
final class Envs implements AppEnvFields {
factory Envs() => _instance;
static const bool kDebugMode = true;
static final dynamic _instance = kDebugMode ? _Staging() : _Prod();
@override
@EnviedField(varName: 'REST_API_URL')
final String apiUrl = _instance.apiUrl;
}
Add strict-casts to analysis_options.yaml:
analyzer:
language:
strict-casts: true
Run build_runner:
flutter pub run build_runner build
Expected Behavior
The code should generate successfully, and the Envs class should work without any linting or type errors.
Actual Behavior
The following error occurs:
A value of type 'dynamic' can't be returned from the constructor 'Envs' because it has a return type of 'Envs'.dart(return_of_invalid_type)
The issue is caused by the line:
factory Envs() => _instance;
The text was updated successfully, but these errors were encountered:
Description
The new feature of Multiple Generations for the Same Class #124 introduces an issue when the strict-casts language rule is enabled in the analysis_options.yaml. This causes a type error when generating code using build_runner.
Steps to Reproduce
Create
app_env_fields.dart
:Create
envs.env.dart
:Add strict-casts to
analysis_options.yaml
:Run build_runner:
flutter pub run build_runner build
Expected Behavior
The code should generate successfully, and the Envs class should work without any linting or type errors.
Actual Behavior
The following error occurs:
A value of type 'dynamic' can't be returned from the constructor 'Envs' because it has a return type of 'Envs'.dart(return_of_invalid_type)
The issue is caused by the line:
factory Envs() => _instance;
The text was updated successfully, but these errors were encountered: