Skip to content

ternary expression behaviour differs in debug mode from profile mode or release mode #98967

Closed
@Kylin3216

Description

@Kylin3216

Bug Description

the value of the '_selectedIndex != null ? _selectedIndex == index : false' is same with '_selectedIndex==index' in debug mode but different in profile or release mode.

Flutter Version

Flutter 2.10.2 • channel stable • https://github.com/flutter/flutter.git
Framework • revision 097d3313d8 (4 days ago) • 2022-02-18 19:33:08 -0600
Engine • revision a83ed0e5e3
Tools • Dart 2.16.1 • DevTools 2.9.2

Steps to Reproduce

  • flutter run
    the expr _selectedIndex != null ? _selectedIndex == index : false is equal to _selectedIndex==index
  • flutter run --profile or flutter run --release
    the expr _selectedIndex != null ? _selectedIndex == index : false is always false
Code sample
import 'package:flutter/material.dart';

void main() {
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(primarySwatch: Colors.blue),
      home: const MyHomePage(),
    );
  }
}

class MyHomePage extends StatefulWidget {
  const MyHomePage({Key? key}) : super(key: key);

  @override
  State<MyHomePage> createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  int? _selectedIndex;

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: const Text("Bug Test")),
      body: Column(
        children: [
          const Padding(
              padding: EdgeInsets.all(20),
              child: Text(
                "the value of the '_selectedIndex != null ? _selectedIndex == index : false'   is same with '_selectedIndex==index' in debug mode but different in profile or release mode",
                style: TextStyle(fontSize: 16),
              )),
          Expanded(
              child: ListView.builder(
                  itemCount: 2,
                  itemBuilder: (context, index) {
                    return ListTile(
                      onTap: () {
                        setState(() => _selectedIndex = index);
                      },
                      //_selectedIndex != null ? _selectedIndex == index : false
                      title: Text(
                          "selected:${_selectedIndex != null ? _selectedIndex == index : false}"),
                      //_selectedIndex == index
                      subtitle: Text("selected:${_selectedIndex == index}"),
                    );
                  }))        ],
      ),
    );
  }
}

Metadata

Metadata

Assignees

Labels

a: releaseChallenges faced when attempting to productionize an appc: regressionIt was better in the past than it is nowdependency: dartDart team may need to help usfound in release: 2.10Found to occur in 2.10found in release: 2.11Found to occur in 2.11has reproducible stepsThe issue has been confirmed reproducible and is ready to work onr: fixedIssue is closed as already fixed in a newer version

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions