Skip to content

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

Closed
@Heewookji

Description

@Heewookji
#### 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');
    }
  }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-vmUse area-vm for VM related issues, including code coverage, and the AOT and JIT backends.type-bugIncorrect behavior (everything from a crash to more subtle misbehavior)

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions