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

if-case gives different results in debug and release mode #57009

Closed
Heewookji opened this issue Nov 1, 2024 · 6 comments
Closed

if-case gives different results in debug and release mode #57009

Heewookji opened this issue Nov 1, 2024 · 6 comments
Labels
area-vm Use area-vm for VM related issues, including code coverage, and the AOT and JIT backends. type-bug Incorrect behavior (everything from a crash to more subtle misbehavior)

Comments

@Heewookji
Copy link

Heewookji commented Nov 1, 2024

#### General info

- Dart 3.5.4 (stable) (Wed Oct 16 16:18:51 2024 +0000) on "macos_arm64"
- on macos / Version 14.3.1 (Build 23D60)

The code below has different print results depending on debug and release modes.
debug : it is not String null
release: it is String null

void main() {
  TestClass(type: TestType.a).run();
}

enum TestType {
  a,
  b,
}

class TestClass {
  TestClass({
    required this.type,
  });

  final TestType type;

  String? get _subtitle {
    return type == TestType.a ? null : 'test subtitle';
  }

  void run() {
    if (_subtitle case String _) {
      print('it is String $_subtitle');
    } else {
      print('it is not String $_subtitle');
    }
  }
}
@dart-github-bot
Copy link
Collaborator

Summary: The if-case statement in the provided code produces different output in debug and release modes. In debug mode, it prints "it is not String null", while in release mode, it prints "it is String null". This discrepancy suggests a potential bug related to type inference or optimization in the if-case statement.

@dart-github-bot dart-github-bot added area-language Dart language related items (some items might be better tracked at github.com/dart-lang/language). triage-automation See https://github.com/dart-lang/ecosystem/tree/main/pkgs/sdk_triage_bot. type-bug Incorrect behavior (everything from a crash to more subtle misbehavior) labels Nov 1, 2024
@parlough
Copy link
Member

parlough commented Nov 1, 2024

Thanks for opening an issue!

Could you provide more information about what debug and release modes are you talking about? How are you building and running the app to get each result?

@Heewookji
Copy link
Author

Heewookji commented Nov 1, 2024

@parlough
After creating a sample app using flutter create, I ran the main code above using flutter run in debug mode and flutter run --release in release mode. (with android simulator)

@julemand101
Copy link
Contributor

I can reproduce this with normal Dart:

> dart --version
Dart SDK version: 3.5.4 (stable) (Wed Oct 16 16:18:51 2024 +0000) on "windows_x64"
> dart .\bug.dart
it is not String null
> dart compile exe bug.dart
Generated: <hidden>\bug.exe
> .\bug.exe 
it is String null

@julemand101
Copy link
Contributor

Testing with latest beta release, I can no longer reproduce the issue:

dart.exe --version
Dart SDK version: 3.6.0-334.3.beta (beta) (Fri Oct 11 09:25:26 2024 +0000) on "windows_x64"
> dart.exe bug.dart
it is not String null
> dart.exe compile exe bug.dart
Generated: <hidden>\bug.exe
> .\bug.exe
it is not String null

@lrhn lrhn added area-vm Use area-vm for VM related issues, including code coverage, and the AOT and JIT backends. and removed area-language Dart language related items (some items might be better tracked at github.com/dart-lang/language). triage-automation See https://github.com/dart-lang/ecosystem/tree/main/pkgs/sdk_triage_bot. labels Nov 2, 2024
@mraleph
Copy link
Member

mraleph commented Nov 4, 2024

I think this was fixed by 36054ee

@mraleph mraleph closed this as completed Nov 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-vm Use area-vm for VM related issues, including code coverage, and the AOT and JIT backends. type-bug Incorrect behavior (everything from a crash to more subtle misbehavior)
Projects
None yet
Development

No branches or pull requests

6 participants