[pkg/vm] Create @pragma("vm:platform-const-if", <cond>) annotation

If a static field or getter is annotated with
@pragma("vm:platform-const-if", <cond>) and <cond> const evaluates
to true, then uses of the static field or getter are const evaluated
when a target operating system is available. If <cond> const evaluates
to any other value, then the annotation is ignored.

For example, when runtime-only code is guarded like the following,
using Flutter's kDebugMode constant, then debug mode Flutter programs
can alter the defaultTargetPlatform for testing, but in release mode,
the defaultTargetPlatform getter is const evaluated and code guarded
with defaultTargetPlatform checks can be eliminated if unreachable:

  @pragma("vm:platform-const-if", !kDebugMode)
  TargetPlatform get defaultTargetPlatform {
   ...
   assert(() {
     if (Platform.environment.containsKey('FLUTTER_TEST')) {
       result = TestPlatform.android;
     }
     return true;
   }());
   if (kDebugMode &&
       platform.debugDefaultTargetPlatformOverride != null) {
     result = platform.debugDefaultTargetPlatformOverride;
   }
   ...
  }

TEST=pkg/vm/test/transformations/vm_constant_evaluator

Change-Id: I55b88502a908c56cf42a761dd06741f15c8a23d9
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/333220
Reviewed-by: Alexander Markov <alexmarkov@google.com>
Reviewed-by: Chloe Stefantsova <cstefantsova@google.com>
Commit-Queue: Tess Strickland <sstrickl@google.com>
diff --git a/pkg/front_end/lib/src/fasta/kernel/constant_evaluator.dart b/pkg/front_end/lib/src/fasta/kernel/constant_evaluator.dart
index d121726..1f669ee 100644
--- a/pkg/front_end/lib/src/fasta/kernel/constant_evaluator.dart
+++ b/pkg/front_end/lib/src/fasta/kernel/constant_evaluator.dart
@@ -763,8 +763,12 @@
       if (shouldInline(target.initializer!)) {
         return evaluateAndTransformWithContext(node, node);
       }
-    } else if (target is Procedure && target.kind == ProcedureKind.Method) {
-      return evaluateAndTransformWithContext(node, node);
+    } else if (target is Procedure) {
+      if (target.kind == ProcedureKind.Method) {
+        return evaluateAndTransformWithContext(node, node);
+      } else if (target.kind == ProcedureKind.Getter && enableConstFunctions) {
+        return evaluateAndTransformWithContext(node, node);
+      }
     }
     return super.visitStaticGet(node, removalSentinel);
   }
@@ -2443,7 +2447,8 @@
   final EvaluationMode evaluationMode;
 
   final bool enableTripleShift;
-  final bool enableConstFunctions;
+  final bool enableAsserts;
+  bool enableConstFunctions;
   bool inExtensionTypeConstConstructor = false;
 
   final Map<Constant, Constant> canonicalizationCache;
@@ -2488,6 +2493,7 @@
       this._environmentDefines, this.typeEnvironment, this.errorReporter,
       {this.enableTripleShift = false,
       this.enableConstFunctions = false,
+      this.enableAsserts = true,
       this.errorOnUnevaluatedConstant = false,
       this.evaluationMode = EvaluationMode.weak})
       : numberSemantics = backend.numberSemantics,
@@ -3692,6 +3698,7 @@
   /// Returns [null] on success and an error-"constant" on failure, as such the
   /// return value should be checked.
   AbortConstant? checkAssert(AssertStatement statement) {
+    if (!enableAsserts) return null;
     final Constant condition = _evaluateSubexpression(statement.condition);
     if (condition is AbortConstant) return condition;
 
@@ -4577,27 +4584,23 @@
 
   @override
   Constant visitStaticGet(StaticGet node) {
-    return withNewEnvironment(() {
-      final Member target = node.target;
-      visitedLibraries.add(target.enclosingLibrary);
-      if (target is Field) {
-        if (target.isConst) {
-          return evaluateExpressionInContext(target, target.initializer!);
-        }
-        return createEvaluationErrorConstant(
-            node,
-            templateConstEvalInvalidStaticInvocation
-                .withArguments(target.name.text));
-      } else if (target is Procedure && target.kind == ProcedureKind.Method) {
+    final Member target = node.target;
+    visitedLibraries.add(target.enclosingLibrary);
+    if (target is Field && target.isConst) {
+      return withNewEnvironment(
+          () => evaluateExpressionInContext(target, target.initializer!));
+    } else if (target is Procedure) {
+      if (target.kind == ProcedureKind.Method) {
         // TODO(johnniwinther): Remove this. This should never occur.
         return canonicalize(new StaticTearOffConstant(target));
-      } else {
-        return createEvaluationErrorConstant(
-            node,
-            templateConstEvalInvalidStaticInvocation
-                .withArguments(target.name.text));
+      } else if (target.kind == ProcedureKind.Getter && enableConstFunctions) {
+        return _handleFunctionInvocation(target.function, [], [], {});
       }
-    });
+    }
+    return createEvaluationErrorConstant(
+        node,
+        templateConstEvalInvalidStaticInvocation
+            .withArguments(target.name.text));
   }
 
   @override
@@ -5617,6 +5620,7 @@
 
   @override
   ExecutionStatus visitAssertBlock(AssertBlock node) {
+    if (!exprEvaluator.enableAsserts) return const ProceedStatus();
     throw new UnsupportedError(
         'Statement constant evaluation does not support ${node.runtimeType}.');
   }
diff --git a/pkg/vm/lib/kernel_front_end.dart b/pkg/vm/lib/kernel_front_end.dart
index 0b6c91f..74143be 100644
--- a/pkg/vm/lib/kernel_front_end.dart
+++ b/pkg/vm/lib/kernel_front_end.dart
@@ -577,7 +577,9 @@
   final os = targetOS != null ? TargetOS.fromString(targetOS)! : null;
   final evaluator = vm_constant_evaluator.VMConstantEvaluator.create(
       target, component, os, nnbdMode,
-      environmentDefines: environmentDefines, coreTypes: coreTypes);
+      enableAsserts: enableAsserts,
+      environmentDefines: environmentDefines,
+      coreTypes: coreTypes);
   unreachable_code_elimination.transformComponent(
       target, component, evaluator, enableAsserts);
 
diff --git a/pkg/vm/lib/transformations/pragma.dart b/pkg/vm/lib/transformations/pragma.dart
index 999787a..0479735 100644
--- a/pkg/vm/lib/transformations/pragma.dart
+++ b/pkg/vm/lib/transformations/pragma.dart
@@ -15,60 +15,66 @@
 const kVmRecognizedPragmaName = "vm:recognized";
 const kVmDisableUnboxedParametersPragmaName = "vm:disable-unboxed-parameters";
 const kVmKeepNamePragmaName = "vm:keep-name";
+const kVmPlatformConstPragmaName = "vm:platform-const";
+const kVmPlatformConstIfPragmaName = "vm:platform-const-if";
 
 // Pragmas recognized by dart2wasm
 const kWasmEntryPointPragmaName = "wasm:entry-point";
 const kWasmExportPragmaName = "wasm:export";
 
-abstract class ParsedPragma {
-  const ParsedPragma();
-}
+abstract class ParsedPragma {}
 
 enum PragmaEntryPointType { Default, GetterOnly, SetterOnly, CallOnly }
 
 enum PragmaRecognizedType { AsmIntrinsic, GraphIntrinsic, Other }
 
-class ParsedEntryPointPragma extends ParsedPragma {
+class ParsedEntryPointPragma implements ParsedPragma {
   final PragmaEntryPointType type;
   const ParsedEntryPointPragma(this.type);
 }
 
-class ParsedResultTypeByTypePragma extends ParsedPragma {
+class ParsedResultTypeByTypePragma implements ParsedPragma {
   final DartType type;
   final bool resultTypeUsesPassedTypeArguments;
   const ParsedResultTypeByTypePragma(
       this.type, this.resultTypeUsesPassedTypeArguments);
 }
 
-class ParsedResultTypeByPathPragma extends ParsedPragma {
+class ParsedResultTypeByPathPragma implements ParsedPragma {
   final String path;
   const ParsedResultTypeByPathPragma(this.path);
 }
 
-class ParsedNonNullableResultType extends ParsedPragma {
+class ParsedNonNullableResultType implements ParsedPragma {
   const ParsedNonNullableResultType();
 }
 
-class ParsedRecognized extends ParsedPragma {
+class ParsedRecognized implements ParsedPragma {
   final PragmaRecognizedType type;
   const ParsedRecognized(this.type);
 }
 
-class ParsedDisableUnboxedParameters extends ParsedPragma {
+class ParsedDisableUnboxedParameters implements ParsedPragma {
   const ParsedDisableUnboxedParameters();
 }
 
-class ParsedKeepNamePragma extends ParsedPragma {
+class ParsedKeepNamePragma implements ParsedPragma {
   const ParsedKeepNamePragma();
 }
 
+class ParsedPlatformConstPragma implements ParsedPragma {
+  const ParsedPlatformConstPragma();
+}
+
 abstract class PragmaAnnotationParser {
   /// May return 'null' if the annotation does not represent a recognized
   /// @pragma.
   ParsedPragma? parsePragma(Expression annotation);
+
+  Iterable<R> parsedPragmas<R extends ParsedPragma>(Iterable<Expression> node);
 }
 
-class ConstantPragmaAnnotationParser extends PragmaAnnotationParser {
+class ConstantPragmaAnnotationParser implements PragmaAnnotationParser {
   final CoreTypes coreTypes;
   final Target target;
 
@@ -166,6 +172,14 @@
         return const ParsedDisableUnboxedParameters();
       case kVmKeepNamePragmaName:
         return ParsedKeepNamePragma();
+      case kVmPlatformConstPragmaName:
+        return ParsedPlatformConstPragma();
+      case kVmPlatformConstIfPragmaName:
+        if (options is! BoolConstant) {
+          throw "ERROR: Non-boolean option to '$kVmPlatformConstIfPragmaName' "
+              "pragma: $options";
+        }
+        return options.value ? ParsedPlatformConstPragma() : null;
       case kWasmEntryPointPragmaName:
         return ParsedEntryPointPragma(PragmaEntryPointType.Default);
       case kWasmExportPragmaName:
@@ -175,4 +189,8 @@
         return null;
     }
   }
+
+  Iterable<R> parsedPragmas<R extends ParsedPragma>(
+          Iterable<Expression> annotations) =>
+      annotations.map(parsePragma).whereType<R>();
 }
diff --git a/pkg/vm/lib/transformations/unreachable_code_elimination.dart b/pkg/vm/lib/transformations/unreachable_code_elimination.dart
index 091d0f8..4c6b788 100644
--- a/pkg/vm/lib/transformations/unreachable_code_elimination.dart
+++ b/pkg/vm/lib/transformations/unreachable_code_elimination.dart
@@ -48,25 +48,10 @@
     return constant is BoolConstant ? constant.value : null;
   }
 
-  Expression _makeConstantExpression(Constant constant, Expression node) {
-    if (constant is UnevaluatedConstant &&
-        constant.expression is InvalidExpression) {
-      return constant.expression;
-    }
-    ConstantExpression constantExpression = new ConstantExpression(
-        constant, node.getStaticType(_staticTypeContext!))
-      ..fileOffset = node.fileOffset;
-    if (node is FileUriExpression) {
-      return new FileUriConstantExpression(constantExpression.constant,
-          type: constantExpression.type, fileUri: node.fileUri)
-        ..fileOffset = node.fileOffset;
-    }
-    return constantExpression;
-  }
-
   Expression _createBoolConstantExpression(bool value, Expression node) =>
-      _makeConstantExpression(
-          constantEvaluator.canonicalize(BoolConstant(value)), node);
+      ConstantExpression(constantEvaluator.makeBoolConstant(value),
+          node.getStaticType(_staticTypeContext!))
+        ..fileOffset = node.fileOffset;
 
   Statement _makeEmptyBlockIfEmptyStatement(Statement node, TreeNode parent) =>
       node is EmptyStatement ? (Block(<Statement>[])..parent = parent) : node;
@@ -219,11 +204,21 @@
     if (target is Field && target.isConst) {
       throw 'StaticGet from const field $target should be evaluated by front-end: $node';
     }
-    if (!constantEvaluator.transformerShouldEvaluateExpression(node)) {
-      return node;
+
+    if (!constantEvaluator.hasTargetOS ||
+        !constantEvaluator.isPlatformConst(target)) {
+      return super.visitStaticGet(node, removalSentinel);
     }
+
     final result = constantEvaluator.evaluate(_staticTypeContext!, node);
-    return _makeConstantExpression(result, node);
+
+    if (result is UnevaluatedConstant &&
+        result.expression is InvalidExpression) {
+      return result.expression;
+    }
+
+    final type = node.getStaticType(_staticTypeContext!);
+    return ConstantExpression(result, type)..fileOffset = node.fileOffset;
   }
 
   @override
diff --git a/pkg/vm/lib/transformations/vm_constant_evaluator.dart b/pkg/vm/lib/transformations/vm_constant_evaluator.dart
index 63ab64e..2a09c0e 100644
--- a/pkg/vm/lib/transformations/vm_constant_evaluator.dart
+++ b/pkg/vm/lib/transformations/vm_constant_evaluator.dart
@@ -11,24 +11,16 @@
 
 import 'package:front_end/src/base/nnbd_mode.dart';
 import 'package:front_end/src/fasta/kernel/constant_evaluator.dart'
-    show
-        AbortConstant,
-        AbortStatus,
-        ConstantEvaluator,
-        ErrorReporter,
-        EvaluationMode,
-        ProceedStatus,
-        ReturnStatus,
-        SimpleErrorReporter,
-        StatementConstantEvaluator;
+    show ConstantEvaluator, ErrorReporter, EvaluationMode, SimpleErrorReporter;
 
 import '../target_os.dart';
+import 'pragma.dart';
 
 /// Evaluates uses of static fields and getters using VM-specific and
 /// platform-specific knowledge.
 ///
-/// [targetOS] represents the target operating system and is used when
-/// evaluating static fields and getters annotated with "vm:platform-const".
+/// The provided [TargetOS], when non-null, is used when evaluating static
+/// fields and getters annotated with "vm:platform-const".
 ///
 /// To avoid restricting getters annotated with "vm:platform-const" to be just
 /// a single return statement whose body is evaluated, we treat annotated
@@ -39,8 +31,7 @@
   final Map<String, Constant> _constantFields = {};
 
   final Class? _platformClass;
-  final Class _pragmaClass;
-  final Field _pragmaName;
+  final PragmaAnnotationParser _pragmaParser;
 
   VMConstantEvaluator(
       DartLibrarySupport dartLibrarySupport,
@@ -50,25 +41,26 @@
       TypeEnvironment typeEnvironment,
       ErrorReporter errorReporter,
       this._targetOS,
+      this._pragmaParser,
       {bool enableTripleShift = false,
       bool enableConstFunctions = false,
+      bool enableAsserts = true,
       bool errorOnUnevaluatedConstant = false,
       EvaluationMode evaluationMode = EvaluationMode.weak})
       : _platformClass = typeEnvironment.coreTypes.platformClass,
-        _pragmaClass = typeEnvironment.coreTypes.pragmaClass,
-        _pragmaName = typeEnvironment.coreTypes.pragmaName,
         super(dartLibrarySupport, backend, component, environmentDefines,
             typeEnvironment, errorReporter,
             enableTripleShift: enableTripleShift,
             enableConstFunctions: enableConstFunctions,
+            enableAsserts: enableAsserts,
             errorOnUnevaluatedConstant: errorOnUnevaluatedConstant,
             evaluationMode: evaluationMode) {
     // Only add Platform fields if the Platform class is part of the component
     // being evaluated.
-    final os = _targetOS;
-    if (os != null && _platformClass != null) {
-      _constantFields['operatingSystem'] = StringConstant(os.name);
-      _constantFields['pathSeparator'] = StringConstant(os.pathSeparator);
+    if (_targetOS != null && _platformClass != null) {
+      _constantFields['operatingSystem'] = StringConstant(_targetOS!.name);
+      _constantFields['pathSeparator'] =
+          StringConstant(_targetOS!.pathSeparator);
     }
   }
 
@@ -78,6 +70,7 @@
       bool enableTripleShift = false,
       bool enableConstFunctions = false,
       bool enableConstructorTearOff = false,
+      bool enableAsserts = true,
       bool errorOnUnevaluatedConstant = false,
       Map<String, String>? environmentDefines,
       CoreTypes? coreTypes,
@@ -97,89 +90,62 @@
         component,
         environmentDefines,
         typeEnvironment,
-        SimpleErrorReporter(),
+        const SimpleErrorReporter(),
         targetOS,
+        ConstantPragmaAnnotationParser(coreTypes, target),
         enableTripleShift: enableTripleShift,
         enableConstFunctions: enableConstFunctions,
+        enableAsserts: enableAsserts,
         errorOnUnevaluatedConstant: errorOnUnevaluatedConstant,
         evaluationMode: EvaluationMode.fromNnbdMode(nnbdMode));
   }
 
-  /// Used for methods and fields with initializers where the method body or
-  /// field initializer must evaluate to a constant value when a target
-  /// operating system is provided.
-  static const _constPragmaName = "vm:platform-const";
+  bool get hasTargetOS => _targetOS != null;
 
-  bool _hasAnnotation(Annotatable node, String name) {
-    for (final annotation in node.annotations) {
-      if (annotation is ConstantExpression) {
-        final constant = annotation.constant;
-        if (constant is InstanceConstant &&
-            constant.classNode == _pragmaClass &&
-            constant.fieldValues[_pragmaName.fieldReference] ==
-                StringConstant(name)) {
-          return true;
-        }
-      }
-    }
-    return false;
-  }
-
-  bool _isPlatformConst(Member node) => _hasAnnotation(node, _constPragmaName);
-
-  bool transformerShouldEvaluateExpression(Expression node) =>
-      _targetOS != null && node is StaticGet && _isPlatformConst(node.target);
-
-  Constant _executePlatformConstBody(Statement statement) {
-    final status = statement.accept(StatementConstantEvaluator(this));
-    if (status is AbortStatus) return status.error;
-    // Happens if there is no return statement in a void Function(...) body.
-    if (status is ProceedStatus) return canonicalize(NullConstant());
-    if (status is ReturnStatus) {
-      final value = status.value;
-      return value != null ? value : canonicalize(NullConstant());
-    }
-    // Other statuses denote intermediate states and not final ones.
-    throw 'No valid constant returned after executing $statement';
-  }
+  bool isPlatformConst(Member member) => _pragmaParser
+      .parsedPragmas<ParsedPlatformConstPragma>(member.annotations)
+      .isNotEmpty;
 
   @override
   Constant visitStaticGet(StaticGet node) {
-    assert(_targetOS != null);
+    assert(hasTargetOS);
     final target = node.target;
 
     // This visitor can be called recursively while evaluating an abstraction
     // over the Platform getters and fields, so check that the visited node has
     // an appropriately annotated target.
-    if (!_isPlatformConst(target)) return super.visitStaticGet(node);
+    if (!isPlatformConst(target)) return super.visitStaticGet(node);
 
-    return withNewEnvironment(() {
-      final nameText = target.name.text;
-      visitedLibraries.add(target.enclosingLibrary);
+    visitedLibraries.add(target.enclosingLibrary);
 
-      // First, check for the fields in Platform whose initializers should not
-      // be evaluated, but instead uses of the field should just be replaced
-      // directly with an already calculated constant.
-      if (target is Field && target.enclosingClass == _platformClass) {
-        final constant = _constantFields[nameText];
+    if (target is Field) {
+      // If this is a special Platform field that has a pre-calculated value
+      // for the given operating system, just use the canonicalized value.
+      if (target.enclosingClass == _platformClass) {
+        final constant = _constantFields[target.name.text];
         if (constant != null) {
           return canonicalize(constant);
         }
       }
 
-      late Constant result;
-      if (target is Field && target.initializer != null) {
-        result = evaluateExpressionInContext(target, target.initializer!);
-      } else if (target is Procedure && target.isGetter) {
-        final body = target.function.body!;
-        result = _executePlatformConstBody(body);
+      final initializer = target.initializer;
+      if (initializer == null) {
+        throw 'Cannot const evaluate annotated field with no initializer';
       }
-      if (result is AbortConstant) {
-        throw "The body or initialization of member '$nameText' does not "
-            "evaluate to a constant value for the specified target operating "
-            "system '$_targetOS'.";
-      }
+      return withNewEnvironment(
+          () => evaluateExpressionInContext(target, initializer));
+    }
+
+    if (target is Procedure && target.kind == ProcedureKind.Getter) {
+      // Temporarily enable const functions and use the base class to evaluate
+      // the getter with appropriate caching/recursive evaluation checks.
+      final oldEnableConstFunctions = enableConstFunctions;
+      enableConstFunctions = true;
+      final result = super.visitStaticGet(node);
+      enableConstFunctions = oldEnableConstFunctions;
       return result;
-    });
+    }
+
+    throw 'Expected annotated field with initializer or getter, got $target';
   }
 }
diff --git a/pkg/vm/test/common_test_utils.dart b/pkg/vm/test/common_test_utils.dart
index 5bd1422..b8402e5 100644
--- a/pkg/vm/test/common_test_utils.dart
+++ b/pkg/vm/test/common_test_utils.dart
@@ -157,8 +157,8 @@
   String actual, {
   String expectFilePostfix = '',
 }) {
-  final expectFile =
-      new File('${source.toFilePath()}$expectFilePostfix.expect');
+  final baseFilename = '${source.toFilePath()}$expectFilePostfix';
+  final expectFile = new File('$baseFilename.expect');
   final expected = expectFile.existsSync() ? expectFile.readAsStringSync() : '';
 
   if (actual != expected) {
@@ -167,7 +167,7 @@
       print("  Updated $expectFile");
     } else {
       if (bool.fromEnvironment(kDumpActualResult)) {
-        new File(source.toFilePath() + '.actual').writeAsStringSync(actual);
+        new File('$baseFilename.actual').writeAsStringSync(actual);
       }
       Difference diff = findFirstDifference(actual, expected);
       fail("""
diff --git a/pkg/vm/test/transformations/unreachable_code_elimination_test.dart b/pkg/vm/test/transformations/unreachable_code_elimination_test.dart
index a71c182..e59fcd6 100644
--- a/pkg/vm/test/transformations/unreachable_code_elimination_test.dart
+++ b/pkg/vm/test/transformations/unreachable_code_elimination_test.dart
@@ -34,8 +34,9 @@
         'test.define.isTrue': 'true',
         'test.define.isFalse': 'false'
       });
-  final evaluator =
-      VMConstantEvaluator.create(target, component, targetOS, nnbdMode);
+  final evaluator = VMConstantEvaluator.create(
+      target, component, targetOS, nnbdMode,
+      enableAsserts: enableAsserts);
   component = transformComponent(target, component, evaluator, enableAsserts);
   verifyComponent(
       target, VerificationStage.afterGlobalTransformations, component);
diff --git a/pkg/vm/test/transformations/vm_constant_evaluator_test.dart b/pkg/vm/test/transformations/vm_constant_evaluator_test.dart
index ea615ce..7b944c5 100644
--- a/pkg/vm/test/transformations/vm_constant_evaluator_test.dart
+++ b/pkg/vm/test/transformations/vm_constant_evaluator_test.dart
@@ -21,8 +21,26 @@
 
 final String pkgVmDir = Platform.script.resolve('../..').toFilePath();
 
-runTestCase(Uri source, TargetOS os, String postfix) async {
-  final enableAsserts = false;
+class TestCase {
+  final TargetOS os;
+  final bool debug;
+  final bool enableAsserts;
+
+  const TestCase(this.os, {required this.debug, required this.enableAsserts});
+
+  String postfix() {
+    String result = '.${os.name}';
+    if (debug) {
+      result += '.debug';
+    }
+    if (enableAsserts) {
+      result += '.withAsserts';
+    }
+    return result;
+  }
+}
+
+runTestCase(Uri source, TestCase testCase) async {
   final soundNullSafety = true;
   final nnbdMode = NnbdMode.Strong;
   final target =
@@ -30,17 +48,21 @@
   Component component = await compileTestCaseToKernelProgram(source,
       target: target,
       environmentDefines: {
-        'test.define.isTrue': 'true',
-        'test.define.isFalse': 'false'
+        'test.define.debug': testCase.debug ? 'true' : 'false',
+        'test.define.enableAsserts': testCase.enableAsserts ? 'true' : 'false',
       });
 
-  final evaluator = VMConstantEvaluator.create(target, component, os, nnbdMode);
-  component = transformComponent(target, component, evaluator, enableAsserts);
+  final evaluator = VMConstantEvaluator.create(
+      target, component, testCase.os, nnbdMode,
+      enableAsserts: testCase.enableAsserts);
+  component =
+      transformComponent(target, component, evaluator, testCase.enableAsserts);
   verifyComponent(
       target, VerificationStage.afterGlobalTransformations, component);
 
   final actual = kernelLibraryToString(component.mainMethod!.enclosingLibrary);
-  compareResultWithExpectationsFile(source, actual, expectFilePostfix: postfix);
+  compareResultWithExpectationsFile(source, actual,
+      expectFilePostfix: testCase.postfix());
 }
 
 main() {
@@ -53,9 +75,14 @@
         .reversed) {
       if (entry.path.endsWith(".dart")) {
         for (final os in TargetOS.values) {
-          final postfix = '.${os.name}';
-          test('${entry.path}$postfix',
-              () => runTestCase(entry.uri, os, postfix));
+          for (final enableAsserts in [true, false]) {
+            for (final debug in [true, false]) {
+              final testCase =
+                  TestCase(os, debug: debug, enableAsserts: enableAsserts);
+              test('${entry.path}${testCase.postfix()}',
+                  () => runTestCase(entry.uri, testCase));
+            }
+          }
         }
       }
     }
diff --git a/pkg/vm/testcases/transformations/vm_constant_evaluator/platform_testcases.dart b/pkg/vm/testcases/transformations/vm_constant_evaluator/platform_testcases.dart
index bb3f214..86b94c8 100644
--- a/pkg/vm/testcases/transformations/vm_constant_evaluator/platform_testcases.dart
+++ b/pkg/vm/testcases/transformations/vm_constant_evaluator/platform_testcases.dart
@@ -112,7 +112,7 @@
   if (Platform.isLinux) return TestPlatform.linux;
   if (Platform.isMacOS) return TestPlatform.macos;
   if (Platform.isWindows) return TestPlatform.windows;
-  throw 'Unexpected platform';
+  throw 'Unexpected platform: ${Platform.operatingSystem}';
 }
 
 void testPragma(int i) {
@@ -136,8 +136,117 @@
     case TestPlatform.windows:
       print("is windows");
       break;
-    default:
-      throw "Unexpected platform";
+  }
+}
+
+const bool kDebugMode = bool.fromEnvironment('test.define.debug');
+
+TestPlatform? debugDefaultTestPlatform;
+
+@pragma("vm:platform-const-if", !kDebugMode)
+TestPlatform get defaultTestPlatformOverridableWhenDebug {
+  late TestPlatform result;
+  if (Platform.isAndroid) {
+    result = TestPlatform.android;
+  }
+  if (Platform.isFuchsia) {
+    result = TestPlatform.fuchsia;
+  }
+  if (Platform.isIOS) {
+    result = TestPlatform.ios;
+  }
+  if (Platform.isLinux) {
+    result = TestPlatform.linux;
+  }
+  if (Platform.isMacOS) {
+    result = TestPlatform.macos;
+  }
+  if (Platform.isWindows) {
+    result = TestPlatform.windows;
+  }
+  if (kDebugMode && debugDefaultTestPlatform != null) {
+    result = debugDefaultTestPlatform!;
+  }
+  return result;
+}
+
+void testConditionalPragma(int i) {
+  print(defaultTestPlatformOverridableWhenDebug);
+  switch (defaultTestPlatformOverridableWhenDebug) {
+    case TestPlatform.android:
+      print("is android");
+      break;
+    case TestPlatform.fuchsia:
+      print("is fuchsia");
+      break;
+    case TestPlatform.ios:
+      print("is ios");
+      break;
+    case TestPlatform.linux:
+      print("is linux");
+      break;
+    case TestPlatform.macos:
+      print("is macos");
+      break;
+    case TestPlatform.windows:
+      print("is windows");
+      break;
+  }
+}
+
+const bool enableAsserts = bool.fromEnvironment('test.define.enableAsserts');
+
+@pragma("vm:platform-const-if", !enableAsserts)
+TestPlatform get defaultTestPlatformOverridableWithAsserts {
+  late TestPlatform result;
+  if (Platform.isAndroid) {
+    result = TestPlatform.android;
+  }
+  if (Platform.isFuchsia) {
+    result = TestPlatform.fuchsia;
+  }
+  if (Platform.isIOS) {
+    result = TestPlatform.ios;
+  }
+  if (Platform.isLinux) {
+    result = TestPlatform.linux;
+  }
+  if (Platform.isMacOS) {
+    result = TestPlatform.macos;
+  }
+  if (Platform.isWindows) {
+    result = TestPlatform.windows;
+  }
+  assert(() {
+    if (Platform.environment.containsKey('FLUTTER_TEST')) {
+      result = TestPlatform.android;
+    }
+    return true;
+  }());
+  return result;
+}
+
+void testConditionalPragmaWithAsserts(int i) {
+  print(defaultTestPlatformOverridableWithAsserts);
+  switch (defaultTestPlatformOverridableWithAsserts) {
+    case TestPlatform.android:
+      print("is android");
+      break;
+    case TestPlatform.fuchsia:
+      print("is fuchsia");
+      break;
+    case TestPlatform.ios:
+      print("is ios");
+      break;
+    case TestPlatform.linux:
+      print("is linux");
+      break;
+    case TestPlatform.macos:
+      print("is macos");
+      break;
+    case TestPlatform.windows:
+      print("is windows");
+      break;
   }
 }
 
@@ -152,4 +261,7 @@
   testWindows(i);
   testSwitchStatements(i);
   testPragma(i);
+  debugDefaultTestPlatform = TestPlatform.android;
+  testConditionalPragma(i);
+  testConditionalPragmaWithAsserts(i);
 }
diff --git a/pkg/vm/testcases/transformations/vm_constant_evaluator/platform_testcases.dart.android.debug.expect b/pkg/vm/testcases/transformations/vm_constant_evaluator/platform_testcases.dart.android.debug.expect
new file mode 100644
index 0000000..e17f6ac
--- /dev/null
+++ b/pkg/vm/testcases/transformations/vm_constant_evaluator/platform_testcases.dart.android.debug.expect
@@ -0,0 +1,188 @@
+library #lib;
+import self as self;
+import "dart:core" as core;
+
+import "dart:io";
+
+class TestPlatform extends core::_Enum /*isEnum*/  {
+  static const field core::List<self::TestPlatform> values = #C19;
+  enum-element static const field self::TestPlatform android = #C3;
+  enum-element static const field self::TestPlatform fuchsia = #C6;
+  enum-element static const field self::TestPlatform ios = #C9;
+  enum-element static const field self::TestPlatform linux = #C12;
+  enum-element static const field self::TestPlatform macos = #C15;
+  enum-element static const field self::TestPlatform windows = #C18;
+  const synthetic constructor •(core::int #index, core::String #name) → self::TestPlatform
+    : super core::_Enum::•(#index, #name)
+    ;
+  method _enumToString() → core::String
+    return "TestPlatform.${this.{core::_Enum::_name}{core::String}}";
+}
+static const field core::bool kDebugMode = #C20;
+static field self::TestPlatform? debugDefaultTestPlatform;
+static const field core::bool enableAsserts = #C21;
+static method testAndroid(core::int i) → void {
+  final core::bool b = #C20;
+  core::print(b);
+  {
+    final core::String os = #C2;
+    core::print(os);
+    final core::String sep = #C22;
+    core::print(sep);
+  }
+}
+static method testFuchsia(core::int i) → void {
+  final core::bool b = #C21;
+  core::print(b);
+}
+static method testIOS(core::int i) → void {
+  final core::bool b = #C21;
+  core::print(b);
+}
+static method testLinux(core::int i) → void {
+  final core::bool b = #C21;
+  core::print(b);
+}
+static method testMacOS(core::int i) → void {
+  final core::bool b = #C21;
+  core::print(b);
+}
+static method testWindows(core::int i) → void {
+  final core::bool b = #C21;
+  core::print(b);
+}
+static method testSwitchStatements(core::int i) → void {
+  #L1:
+  {
+    core::print("is android");
+    break #L1;
+  }
+}
+@#C25
+static get defaultTestPlatform() → self::TestPlatform {
+  return #C3;
+  throw "Unexpected platform: ${#C2}";
+}
+static method testPragma(core::int i) → void {
+  core::print(#C3);
+  #L2:
+  {
+    core::print("is android");
+    break #L2;
+  }
+}
+@#C27
+static get defaultTestPlatformOverridableWhenDebug() → self::TestPlatform {
+  late self::TestPlatform result;
+  {
+    result = #C3;
+  }
+  if(!(self::debugDefaultTestPlatform == null)) {
+    result = self::debugDefaultTestPlatform!;
+  }
+  return result;
+}
+static method testConditionalPragma(core::int i) → void {
+  core::print(self::defaultTestPlatformOverridableWhenDebug);
+  #L3:
+  switch(self::defaultTestPlatformOverridableWhenDebug) /* isExplicitlyExhaustive, self::TestPlatform */ {
+    #L4:
+    case #C3:
+      {
+        core::print("is android");
+        break #L3;
+      }
+    #L5:
+    case #C6:
+      {
+        core::print("is fuchsia");
+        break #L3;
+      }
+    #L6:
+    case #C9:
+      {
+        core::print("is ios");
+        break #L3;
+      }
+    #L7:
+    case #C12:
+      {
+        core::print("is linux");
+        break #L3;
+      }
+    #L8:
+    case #C15:
+      {
+        core::print("is macos");
+        break #L3;
+      }
+    #L9:
+    case #C18:
+      {
+        core::print("is windows");
+        break #L3;
+      }
+  }
+}
+@#C28
+static get defaultTestPlatformOverridableWithAsserts() → self::TestPlatform {
+  late self::TestPlatform result;
+  {
+    result = #C3;
+  }
+  return result;
+}
+static method testConditionalPragmaWithAsserts(core::int i) → void {
+  core::print(#C3);
+  #L10:
+  {
+    core::print("is android");
+    break #L10;
+  }
+}
+static method main(core::List<core::String> args) → dynamic {
+  if(args.{core::Iterable::isEmpty}{core::bool})
+    return;
+  final core::int i = core::int::parse(args.{core::List::[]}(0){(core::int) → core::String});
+  self::testAndroid(i);
+  self::testFuchsia(i);
+  self::testIOS(i);
+  self::testLinux(i);
+  self::testMacOS(i);
+  self::testWindows(i);
+  self::testSwitchStatements(i);
+  self::testPragma(i);
+  self::debugDefaultTestPlatform = #C3;
+  self::testConditionalPragma(i);
+  self::testConditionalPragmaWithAsserts(i);
+}
+constants  {
+  #C1 = 0
+  #C2 = "android"
+  #C3 = self::TestPlatform {index:#C1, _name:#C2}
+  #C4 = 1
+  #C5 = "fuchsia"
+  #C6 = self::TestPlatform {index:#C4, _name:#C5}
+  #C7 = 2
+  #C8 = "ios"
+  #C9 = self::TestPlatform {index:#C7, _name:#C8}
+  #C10 = 3
+  #C11 = "linux"
+  #C12 = self::TestPlatform {index:#C10, _name:#C11}
+  #C13 = 4
+  #C14 = "macos"
+  #C15 = self::TestPlatform {index:#C13, _name:#C14}
+  #C16 = 5
+  #C17 = "windows"
+  #C18 = self::TestPlatform {index:#C16, _name:#C17}
+  #C19 = <self::TestPlatform>[#C3, #C6, #C9, #C12, #C15, #C18]
+  #C20 = true
+  #C21 = false
+  #C22 = "/"
+  #C23 = "vm:platform-const"
+  #C24 = null
+  #C25 = core::pragma {name:#C23, options:#C24}
+  #C26 = "vm:platform-const-if"
+  #C27 = core::pragma {name:#C26, options:#C21}
+  #C28 = core::pragma {name:#C26, options:#C20}
+}
diff --git a/pkg/vm/testcases/transformations/vm_constant_evaluator/platform_testcases.dart.android.debug.withAsserts.expect b/pkg/vm/testcases/transformations/vm_constant_evaluator/platform_testcases.dart.android.debug.withAsserts.expect
new file mode 100644
index 0000000..566f175
--- /dev/null
+++ b/pkg/vm/testcases/transformations/vm_constant_evaluator/platform_testcases.dart.android.debug.withAsserts.expect
@@ -0,0 +1,228 @@
+library #lib;
+import self as self;
+import "dart:core" as core;
+import "dart:io" as io;
+
+import "dart:io";
+
+class TestPlatform extends core::_Enum /*isEnum*/  {
+  static const field core::List<self::TestPlatform> values = #C19;
+  enum-element static const field self::TestPlatform android = #C3;
+  enum-element static const field self::TestPlatform fuchsia = #C6;
+  enum-element static const field self::TestPlatform ios = #C9;
+  enum-element static const field self::TestPlatform linux = #C12;
+  enum-element static const field self::TestPlatform macos = #C15;
+  enum-element static const field self::TestPlatform windows = #C18;
+  const synthetic constructor •(core::int #index, core::String #name) → self::TestPlatform
+    : super core::_Enum::•(#index, #name)
+    ;
+  method _enumToString() → core::String
+    return "TestPlatform.${this.{core::_Enum::_name}{core::String}}";
+}
+static const field core::bool kDebugMode = #C20;
+static field self::TestPlatform? debugDefaultTestPlatform;
+static const field core::bool enableAsserts = #C20;
+static method testAndroid(core::int i) → void {
+  final core::bool b = #C20;
+  core::print(b);
+  {
+    final core::String os = #C2;
+    core::print(os);
+    final core::String sep = #C21;
+    core::print(sep);
+  }
+}
+static method testFuchsia(core::int i) → void {
+  final core::bool b = #C22;
+  core::print(b);
+}
+static method testIOS(core::int i) → void {
+  final core::bool b = #C22;
+  core::print(b);
+}
+static method testLinux(core::int i) → void {
+  final core::bool b = #C22;
+  core::print(b);
+}
+static method testMacOS(core::int i) → void {
+  final core::bool b = #C22;
+  core::print(b);
+}
+static method testWindows(core::int i) → void {
+  final core::bool b = #C22;
+  core::print(b);
+}
+static method testSwitchStatements(core::int i) → void {
+  #L1:
+  {
+    core::print("is android");
+    break #L1;
+  }
+}
+@#C25
+static get defaultTestPlatform() → self::TestPlatform {
+  return #C3;
+  throw "Unexpected platform: ${#C2}";
+}
+static method testPragma(core::int i) → void {
+  core::print(#C3);
+  #L2:
+  {
+    core::print("is android");
+    break #L2;
+  }
+}
+@#C27
+static get defaultTestPlatformOverridableWhenDebug() → self::TestPlatform {
+  late self::TestPlatform result;
+  {
+    result = #C3;
+  }
+  if(!(self::debugDefaultTestPlatform == null)) {
+    result = self::debugDefaultTestPlatform!;
+  }
+  return result;
+}
+static method testConditionalPragma(core::int i) → void {
+  core::print(self::defaultTestPlatformOverridableWhenDebug);
+  #L3:
+  switch(self::defaultTestPlatformOverridableWhenDebug) /* isExplicitlyExhaustive, self::TestPlatform */ {
+    #L4:
+    case #C3:
+      {
+        core::print("is android");
+        break #L3;
+      }
+    #L5:
+    case #C6:
+      {
+        core::print("is fuchsia");
+        break #L3;
+      }
+    #L6:
+    case #C9:
+      {
+        core::print("is ios");
+        break #L3;
+      }
+    #L7:
+    case #C12:
+      {
+        core::print("is linux");
+        break #L3;
+      }
+    #L8:
+    case #C15:
+      {
+        core::print("is macos");
+        break #L3;
+      }
+    #L9:
+    case #C18:
+      {
+        core::print("is windows");
+        break #L3;
+      }
+  }
+}
+@#C27
+static get defaultTestPlatformOverridableWithAsserts() → self::TestPlatform {
+  late self::TestPlatform result;
+  {
+    result = #C3;
+  }
+  assert((() → core::bool {
+    if(io::Platform::environment.{core::Map::containsKey}("FLUTTER_TEST"){(core::Object?) → core::bool}) {
+      result = #C3;
+    }
+    return true;
+  })(){() → core::bool});
+  return result;
+}
+static method testConditionalPragmaWithAsserts(core::int i) → void {
+  core::print(self::defaultTestPlatformOverridableWithAsserts);
+  #L10:
+  switch(self::defaultTestPlatformOverridableWithAsserts) /* isExplicitlyExhaustive, self::TestPlatform */ {
+    #L11:
+    case #C3:
+      {
+        core::print("is android");
+        break #L10;
+      }
+    #L12:
+    case #C6:
+      {
+        core::print("is fuchsia");
+        break #L10;
+      }
+    #L13:
+    case #C9:
+      {
+        core::print("is ios");
+        break #L10;
+      }
+    #L14:
+    case #C12:
+      {
+        core::print("is linux");
+        break #L10;
+      }
+    #L15:
+    case #C15:
+      {
+        core::print("is macos");
+        break #L10;
+      }
+    #L16:
+    case #C18:
+      {
+        core::print("is windows");
+        break #L10;
+      }
+  }
+}
+static method main(core::List<core::String> args) → dynamic {
+  if(args.{core::Iterable::isEmpty}{core::bool})
+    return;
+  final core::int i = core::int::parse(args.{core::List::[]}(0){(core::int) → core::String});
+  self::testAndroid(i);
+  self::testFuchsia(i);
+  self::testIOS(i);
+  self::testLinux(i);
+  self::testMacOS(i);
+  self::testWindows(i);
+  self::testSwitchStatements(i);
+  self::testPragma(i);
+  self::debugDefaultTestPlatform = #C3;
+  self::testConditionalPragma(i);
+  self::testConditionalPragmaWithAsserts(i);
+}
+constants  {
+  #C1 = 0
+  #C2 = "android"
+  #C3 = self::TestPlatform {index:#C1, _name:#C2}
+  #C4 = 1
+  #C5 = "fuchsia"
+  #C6 = self::TestPlatform {index:#C4, _name:#C5}
+  #C7 = 2
+  #C8 = "ios"
+  #C9 = self::TestPlatform {index:#C7, _name:#C8}
+  #C10 = 3
+  #C11 = "linux"
+  #C12 = self::TestPlatform {index:#C10, _name:#C11}
+  #C13 = 4
+  #C14 = "macos"
+  #C15 = self::TestPlatform {index:#C13, _name:#C14}
+  #C16 = 5
+  #C17 = "windows"
+  #C18 = self::TestPlatform {index:#C16, _name:#C17}
+  #C19 = <self::TestPlatform>[#C3, #C6, #C9, #C12, #C15, #C18]
+  #C20 = true
+  #C21 = "/"
+  #C22 = false
+  #C23 = "vm:platform-const"
+  #C24 = null
+  #C25 = core::pragma {name:#C23, options:#C24}
+  #C26 = "vm:platform-const-if"
+  #C27 = core::pragma {name:#C26, options:#C22}
+}
diff --git a/pkg/vm/testcases/transformations/vm_constant_evaluator/platform_testcases.dart.android.expect b/pkg/vm/testcases/transformations/vm_constant_evaluator/platform_testcases.dart.android.expect
index 149bd4a..b002a4b 100644
--- a/pkg/vm/testcases/transformations/vm_constant_evaluator/platform_testcases.dart.android.expect
+++ b/pkg/vm/testcases/transformations/vm_constant_evaluator/platform_testcases.dart.android.expect
@@ -18,34 +18,37 @@
   method _enumToString() → core::String
     return "TestPlatform.${this.{core::_Enum::_name}{core::String}}";
 }
+static const field core::bool kDebugMode = #C20;
+static field self::TestPlatform? debugDefaultTestPlatform;
+static const field core::bool enableAsserts = #C20;
 static method testAndroid(core::int i) → void {
-  final core::bool b = #C20;
+  final core::bool b = #C21;
   core::print(b);
   {
     final core::String os = #C2;
     core::print(os);
-    final core::String sep = #C21;
+    final core::String sep = #C22;
     core::print(sep);
   }
 }
 static method testFuchsia(core::int i) → void {
-  final core::bool b = #C22;
+  final core::bool b = #C20;
   core::print(b);
 }
 static method testIOS(core::int i) → void {
-  final core::bool b = #C22;
+  final core::bool b = #C20;
   core::print(b);
 }
 static method testLinux(core::int i) → void {
-  final core::bool b = #C22;
+  final core::bool b = #C20;
   core::print(b);
 }
 static method testMacOS(core::int i) → void {
-  final core::bool b = #C22;
+  final core::bool b = #C20;
   core::print(b);
 }
 static method testWindows(core::int i) → void {
-  final core::bool b = #C22;
+  final core::bool b = #C20;
   core::print(b);
 }
 static method testSwitchStatements(core::int i) → void {
@@ -58,7 +61,7 @@
 @#C25
 static get defaultTestPlatform() → self::TestPlatform {
   return #C3;
-  throw "Unexpected platform";
+  throw "Unexpected platform: ${#C2}";
 }
 static method testPragma(core::int i) → void {
   core::print(#C3);
@@ -68,6 +71,38 @@
     break #L2;
   }
 }
+@#C27
+static get defaultTestPlatformOverridableWhenDebug() → self::TestPlatform {
+  late self::TestPlatform result;
+  {
+    result = #C3;
+  }
+  return result;
+}
+static method testConditionalPragma(core::int i) → void {
+  core::print(#C3);
+  #L3:
+  {
+    core::print("is android");
+    break #L3;
+  }
+}
+@#C27
+static get defaultTestPlatformOverridableWithAsserts() → self::TestPlatform {
+  late self::TestPlatform result;
+  {
+    result = #C3;
+  }
+  return result;
+}
+static method testConditionalPragmaWithAsserts(core::int i) → void {
+  core::print(#C3);
+  #L4:
+  {
+    core::print("is android");
+    break #L4;
+  }
+}
 static method main(core::List<core::String> args) → dynamic {
   if(args.{core::Iterable::isEmpty}{core::bool})
     return;
@@ -80,6 +115,9 @@
   self::testWindows(i);
   self::testSwitchStatements(i);
   self::testPragma(i);
+  self::debugDefaultTestPlatform = #C3;
+  self::testConditionalPragma(i);
+  self::testConditionalPragmaWithAsserts(i);
 }
 constants  {
   #C1 = 0
@@ -101,10 +139,12 @@
   #C17 = "windows"
   #C18 = self::TestPlatform {index:#C16, _name:#C17}
   #C19 = <self::TestPlatform>[#C3, #C6, #C9, #C12, #C15, #C18]
-  #C20 = true
-  #C21 = "/"
-  #C22 = false
+  #C20 = false
+  #C21 = true
+  #C22 = "/"
   #C23 = "vm:platform-const"
   #C24 = null
   #C25 = core::pragma {name:#C23, options:#C24}
+  #C26 = "vm:platform-const-if"
+  #C27 = core::pragma {name:#C26, options:#C21}
 }
diff --git a/pkg/vm/testcases/transformations/vm_constant_evaluator/platform_testcases.dart.android.withAsserts.expect b/pkg/vm/testcases/transformations/vm_constant_evaluator/platform_testcases.dart.android.withAsserts.expect
new file mode 100644
index 0000000..d1c848a
--- /dev/null
+++ b/pkg/vm/testcases/transformations/vm_constant_evaluator/platform_testcases.dart.android.withAsserts.expect
@@ -0,0 +1,192 @@
+library #lib;
+import self as self;
+import "dart:core" as core;
+import "dart:io" as io;
+
+import "dart:io";
+
+class TestPlatform extends core::_Enum /*isEnum*/  {
+  static const field core::List<self::TestPlatform> values = #C19;
+  enum-element static const field self::TestPlatform android = #C3;
+  enum-element static const field self::TestPlatform fuchsia = #C6;
+  enum-element static const field self::TestPlatform ios = #C9;
+  enum-element static const field self::TestPlatform linux = #C12;
+  enum-element static const field self::TestPlatform macos = #C15;
+  enum-element static const field self::TestPlatform windows = #C18;
+  const synthetic constructor •(core::int #index, core::String #name) → self::TestPlatform
+    : super core::_Enum::•(#index, #name)
+    ;
+  method _enumToString() → core::String
+    return "TestPlatform.${this.{core::_Enum::_name}{core::String}}";
+}
+static const field core::bool kDebugMode = #C20;
+static field self::TestPlatform? debugDefaultTestPlatform;
+static const field core::bool enableAsserts = #C21;
+static method testAndroid(core::int i) → void {
+  final core::bool b = #C21;
+  core::print(b);
+  {
+    final core::String os = #C2;
+    core::print(os);
+    final core::String sep = #C22;
+    core::print(sep);
+  }
+}
+static method testFuchsia(core::int i) → void {
+  final core::bool b = #C20;
+  core::print(b);
+}
+static method testIOS(core::int i) → void {
+  final core::bool b = #C20;
+  core::print(b);
+}
+static method testLinux(core::int i) → void {
+  final core::bool b = #C20;
+  core::print(b);
+}
+static method testMacOS(core::int i) → void {
+  final core::bool b = #C20;
+  core::print(b);
+}
+static method testWindows(core::int i) → void {
+  final core::bool b = #C20;
+  core::print(b);
+}
+static method testSwitchStatements(core::int i) → void {
+  #L1:
+  {
+    core::print("is android");
+    break #L1;
+  }
+}
+@#C25
+static get defaultTestPlatform() → self::TestPlatform {
+  return #C3;
+  throw "Unexpected platform: ${#C2}";
+}
+static method testPragma(core::int i) → void {
+  core::print(#C3);
+  #L2:
+  {
+    core::print("is android");
+    break #L2;
+  }
+}
+@#C27
+static get defaultTestPlatformOverridableWhenDebug() → self::TestPlatform {
+  late self::TestPlatform result;
+  {
+    result = #C3;
+  }
+  return result;
+}
+static method testConditionalPragma(core::int i) → void {
+  core::print(#C3);
+  #L3:
+  {
+    core::print("is android");
+    break #L3;
+  }
+}
+@#C28
+static get defaultTestPlatformOverridableWithAsserts() → self::TestPlatform {
+  late self::TestPlatform result;
+  {
+    result = #C3;
+  }
+  assert((() → core::bool {
+    if(io::Platform::environment.{core::Map::containsKey}("FLUTTER_TEST"){(core::Object?) → core::bool}) {
+      result = #C3;
+    }
+    return true;
+  })(){() → core::bool});
+  return result;
+}
+static method testConditionalPragmaWithAsserts(core::int i) → void {
+  core::print(self::defaultTestPlatformOverridableWithAsserts);
+  #L4:
+  switch(self::defaultTestPlatformOverridableWithAsserts) /* isExplicitlyExhaustive, self::TestPlatform */ {
+    #L5:
+    case #C3:
+      {
+        core::print("is android");
+        break #L4;
+      }
+    #L6:
+    case #C6:
+      {
+        core::print("is fuchsia");
+        break #L4;
+      }
+    #L7:
+    case #C9:
+      {
+        core::print("is ios");
+        break #L4;
+      }
+    #L8:
+    case #C12:
+      {
+        core::print("is linux");
+        break #L4;
+      }
+    #L9:
+    case #C15:
+      {
+        core::print("is macos");
+        break #L4;
+      }
+    #L10:
+    case #C18:
+      {
+        core::print("is windows");
+        break #L4;
+      }
+  }
+}
+static method main(core::List<core::String> args) → dynamic {
+  if(args.{core::Iterable::isEmpty}{core::bool})
+    return;
+  final core::int i = core::int::parse(args.{core::List::[]}(0){(core::int) → core::String});
+  self::testAndroid(i);
+  self::testFuchsia(i);
+  self::testIOS(i);
+  self::testLinux(i);
+  self::testMacOS(i);
+  self::testWindows(i);
+  self::testSwitchStatements(i);
+  self::testPragma(i);
+  self::debugDefaultTestPlatform = #C3;
+  self::testConditionalPragma(i);
+  self::testConditionalPragmaWithAsserts(i);
+}
+constants  {
+  #C1 = 0
+  #C2 = "android"
+  #C3 = self::TestPlatform {index:#C1, _name:#C2}
+  #C4 = 1
+  #C5 = "fuchsia"
+  #C6 = self::TestPlatform {index:#C4, _name:#C5}
+  #C7 = 2
+  #C8 = "ios"
+  #C9 = self::TestPlatform {index:#C7, _name:#C8}
+  #C10 = 3
+  #C11 = "linux"
+  #C12 = self::TestPlatform {index:#C10, _name:#C11}
+  #C13 = 4
+  #C14 = "macos"
+  #C15 = self::TestPlatform {index:#C13, _name:#C14}
+  #C16 = 5
+  #C17 = "windows"
+  #C18 = self::TestPlatform {index:#C16, _name:#C17}
+  #C19 = <self::TestPlatform>[#C3, #C6, #C9, #C12, #C15, #C18]
+  #C20 = false
+  #C21 = true
+  #C22 = "/"
+  #C23 = "vm:platform-const"
+  #C24 = null
+  #C25 = core::pragma {name:#C23, options:#C24}
+  #C26 = "vm:platform-const-if"
+  #C27 = core::pragma {name:#C26, options:#C21}
+  #C28 = core::pragma {name:#C26, options:#C20}
+}
diff --git a/pkg/vm/testcases/transformations/vm_constant_evaluator/platform_testcases.dart.fuchsia.debug.expect b/pkg/vm/testcases/transformations/vm_constant_evaluator/platform_testcases.dart.fuchsia.debug.expect
new file mode 100644
index 0000000..0c51b94
--- /dev/null
+++ b/pkg/vm/testcases/transformations/vm_constant_evaluator/platform_testcases.dart.fuchsia.debug.expect
@@ -0,0 +1,188 @@
+library #lib;
+import self as self;
+import "dart:core" as core;
+
+import "dart:io";
+
+class TestPlatform extends core::_Enum /*isEnum*/  {
+  static const field core::List<self::TestPlatform> values = #C19;
+  enum-element static const field self::TestPlatform android = #C3;
+  enum-element static const field self::TestPlatform fuchsia = #C6;
+  enum-element static const field self::TestPlatform ios = #C9;
+  enum-element static const field self::TestPlatform linux = #C12;
+  enum-element static const field self::TestPlatform macos = #C15;
+  enum-element static const field self::TestPlatform windows = #C18;
+  const synthetic constructor •(core::int #index, core::String #name) → self::TestPlatform
+    : super core::_Enum::•(#index, #name)
+    ;
+  method _enumToString() → core::String
+    return "TestPlatform.${this.{core::_Enum::_name}{core::String}}";
+}
+static const field core::bool kDebugMode = #C20;
+static field self::TestPlatform? debugDefaultTestPlatform;
+static const field core::bool enableAsserts = #C21;
+static method testAndroid(core::int i) → void {
+  final core::bool b = #C21;
+  core::print(b);
+}
+static method testFuchsia(core::int i) → void {
+  final core::bool b = #C20;
+  core::print(b);
+  {
+    final core::String os = #C5;
+    core::print(os);
+    final core::String sep = #C22;
+    core::print(sep);
+  }
+}
+static method testIOS(core::int i) → void {
+  final core::bool b = #C21;
+  core::print(b);
+}
+static method testLinux(core::int i) → void {
+  final core::bool b = #C21;
+  core::print(b);
+}
+static method testMacOS(core::int i) → void {
+  final core::bool b = #C21;
+  core::print(b);
+}
+static method testWindows(core::int i) → void {
+  final core::bool b = #C21;
+  core::print(b);
+}
+static method testSwitchStatements(core::int i) → void {
+  #L1:
+  {
+    core::print("is fuchsia");
+    break #L1;
+  }
+}
+@#C25
+static get defaultTestPlatform() → self::TestPlatform {
+  return #C6;
+  throw "Unexpected platform: ${#C5}";
+}
+static method testPragma(core::int i) → void {
+  core::print(#C6);
+  #L2:
+  {
+    core::print("is fuchsia");
+    break #L2;
+  }
+}
+@#C27
+static get defaultTestPlatformOverridableWhenDebug() → self::TestPlatform {
+  late self::TestPlatform result;
+  {
+    result = #C6;
+  }
+  if(!(self::debugDefaultTestPlatform == null)) {
+    result = self::debugDefaultTestPlatform!;
+  }
+  return result;
+}
+static method testConditionalPragma(core::int i) → void {
+  core::print(self::defaultTestPlatformOverridableWhenDebug);
+  #L3:
+  switch(self::defaultTestPlatformOverridableWhenDebug) /* isExplicitlyExhaustive, self::TestPlatform */ {
+    #L4:
+    case #C3:
+      {
+        core::print("is android");
+        break #L3;
+      }
+    #L5:
+    case #C6:
+      {
+        core::print("is fuchsia");
+        break #L3;
+      }
+    #L6:
+    case #C9:
+      {
+        core::print("is ios");
+        break #L3;
+      }
+    #L7:
+    case #C12:
+      {
+        core::print("is linux");
+        break #L3;
+      }
+    #L8:
+    case #C15:
+      {
+        core::print("is macos");
+        break #L3;
+      }
+    #L9:
+    case #C18:
+      {
+        core::print("is windows");
+        break #L3;
+      }
+  }
+}
+@#C28
+static get defaultTestPlatformOverridableWithAsserts() → self::TestPlatform {
+  late self::TestPlatform result;
+  {
+    result = #C6;
+  }
+  return result;
+}
+static method testConditionalPragmaWithAsserts(core::int i) → void {
+  core::print(#C6);
+  #L10:
+  {
+    core::print("is fuchsia");
+    break #L10;
+  }
+}
+static method main(core::List<core::String> args) → dynamic {
+  if(args.{core::Iterable::isEmpty}{core::bool})
+    return;
+  final core::int i = core::int::parse(args.{core::List::[]}(0){(core::int) → core::String});
+  self::testAndroid(i);
+  self::testFuchsia(i);
+  self::testIOS(i);
+  self::testLinux(i);
+  self::testMacOS(i);
+  self::testWindows(i);
+  self::testSwitchStatements(i);
+  self::testPragma(i);
+  self::debugDefaultTestPlatform = #C3;
+  self::testConditionalPragma(i);
+  self::testConditionalPragmaWithAsserts(i);
+}
+constants  {
+  #C1 = 0
+  #C2 = "android"
+  #C3 = self::TestPlatform {index:#C1, _name:#C2}
+  #C4 = 1
+  #C5 = "fuchsia"
+  #C6 = self::TestPlatform {index:#C4, _name:#C5}
+  #C7 = 2
+  #C8 = "ios"
+  #C9 = self::TestPlatform {index:#C7, _name:#C8}
+  #C10 = 3
+  #C11 = "linux"
+  #C12 = self::TestPlatform {index:#C10, _name:#C11}
+  #C13 = 4
+  #C14 = "macos"
+  #C15 = self::TestPlatform {index:#C13, _name:#C14}
+  #C16 = 5
+  #C17 = "windows"
+  #C18 = self::TestPlatform {index:#C16, _name:#C17}
+  #C19 = <self::TestPlatform>[#C3, #C6, #C9, #C12, #C15, #C18]
+  #C20 = true
+  #C21 = false
+  #C22 = "/"
+  #C23 = "vm:platform-const"
+  #C24 = null
+  #C25 = core::pragma {name:#C23, options:#C24}
+  #C26 = "vm:platform-const-if"
+  #C27 = core::pragma {name:#C26, options:#C21}
+  #C28 = core::pragma {name:#C26, options:#C20}
+}
diff --git a/pkg/vm/testcases/transformations/vm_constant_evaluator/platform_testcases.dart.fuchsia.debug.withAsserts.expect b/pkg/vm/testcases/transformations/vm_constant_evaluator/platform_testcases.dart.fuchsia.debug.withAsserts.expect
new file mode 100644
index 0000000..8d701b2
--- /dev/null
+++ b/pkg/vm/testcases/transformations/vm_constant_evaluator/platform_testcases.dart.fuchsia.debug.withAsserts.expect
@@ -0,0 +1,228 @@
+library #lib;
+import self as self;
+import "dart:core" as core;
+import "dart:io" as io;
+
+import "dart:io";
+
+class TestPlatform extends core::_Enum /*isEnum*/  {
+  static const field core::List<self::TestPlatform> values = #C19;
+  enum-element static const field self::TestPlatform android = #C3;
+  enum-element static const field self::TestPlatform fuchsia = #C6;
+  enum-element static const field self::TestPlatform ios = #C9;
+  enum-element static const field self::TestPlatform linux = #C12;
+  enum-element static const field self::TestPlatform macos = #C15;
+  enum-element static const field self::TestPlatform windows = #C18;
+  const synthetic constructor •(core::int #index, core::String #name) → self::TestPlatform
+    : super core::_Enum::•(#index, #name)
+    ;
+  method _enumToString() → core::String
+    return "TestPlatform.${this.{core::_Enum::_name}{core::String}}";
+}
+static const field core::bool kDebugMode = #C20;
+static field self::TestPlatform? debugDefaultTestPlatform;
+static const field core::bool enableAsserts = #C20;
+static method testAndroid(core::int i) → void {
+  final core::bool b = #C21;
+  core::print(b);
+}
+static method testFuchsia(core::int i) → void {
+  final core::bool b = #C20;
+  core::print(b);
+  {
+    final core::String os = #C5;
+    core::print(os);
+    final core::String sep = #C22;
+    core::print(sep);
+  }
+}
+static method testIOS(core::int i) → void {
+  final core::bool b = #C21;
+  core::print(b);
+}
+static method testLinux(core::int i) → void {
+  final core::bool b = #C21;
+  core::print(b);
+}
+static method testMacOS(core::int i) → void {
+  final core::bool b = #C21;
+  core::print(b);
+}
+static method testWindows(core::int i) → void {
+  final core::bool b = #C21;
+  core::print(b);
+}
+static method testSwitchStatements(core::int i) → void {
+  #L1:
+  {
+    core::print("is fuchsia");
+    break #L1;
+  }
+}
+@#C25
+static get defaultTestPlatform() → self::TestPlatform {
+  return #C6;
+  throw "Unexpected platform: ${#C5}";
+}
+static method testPragma(core::int i) → void {
+  core::print(#C6);
+  #L2:
+  {
+    core::print("is fuchsia");
+    break #L2;
+  }
+}
+@#C27
+static get defaultTestPlatformOverridableWhenDebug() → self::TestPlatform {
+  late self::TestPlatform result;
+  {
+    result = #C6;
+  }
+  if(!(self::debugDefaultTestPlatform == null)) {
+    result = self::debugDefaultTestPlatform!;
+  }
+  return result;
+}
+static method testConditionalPragma(core::int i) → void {
+  core::print(self::defaultTestPlatformOverridableWhenDebug);
+  #L3:
+  switch(self::defaultTestPlatformOverridableWhenDebug) /* isExplicitlyExhaustive, self::TestPlatform */ {
+    #L4:
+    case #C3:
+      {
+        core::print("is android");
+        break #L3;
+      }
+    #L5:
+    case #C6:
+      {
+        core::print("is fuchsia");
+        break #L3;
+      }
+    #L6:
+    case #C9:
+      {
+        core::print("is ios");
+        break #L3;
+      }
+    #L7:
+    case #C12:
+      {
+        core::print("is linux");
+        break #L3;
+      }
+    #L8:
+    case #C15:
+      {
+        core::print("is macos");
+        break #L3;
+      }
+    #L9:
+    case #C18:
+      {
+        core::print("is windows");
+        break #L3;
+      }
+  }
+}
+@#C27
+static get defaultTestPlatformOverridableWithAsserts() → self::TestPlatform {
+  late self::TestPlatform result;
+  {
+    result = #C6;
+  }
+  assert((() → core::bool {
+    if(io::Platform::environment.{core::Map::containsKey}("FLUTTER_TEST"){(core::Object?) → core::bool}) {
+      result = #C3;
+    }
+    return true;
+  })(){() → core::bool});
+  return result;
+}
+static method testConditionalPragmaWithAsserts(core::int i) → void {
+  core::print(self::defaultTestPlatformOverridableWithAsserts);
+  #L10:
+  switch(self::defaultTestPlatformOverridableWithAsserts) /* isExplicitlyExhaustive, self::TestPlatform */ {
+    #L11:
+    case #C3:
+      {
+        core::print("is android");
+        break #L10;
+      }
+    #L12:
+    case #C6:
+      {
+        core::print("is fuchsia");
+        break #L10;
+      }
+    #L13:
+    case #C9:
+      {
+        core::print("is ios");
+        break #L10;
+      }
+    #L14:
+    case #C12:
+      {
+        core::print("is linux");
+        break #L10;
+      }
+    #L15:
+    case #C15:
+      {
+        core::print("is macos");
+        break #L10;
+      }
+    #L16:
+    case #C18:
+      {
+        core::print("is windows");
+        break #L10;
+      }
+  }
+}
+static method main(core::List<core::String> args) → dynamic {
+  if(args.{core::Iterable::isEmpty}{core::bool})
+    return;
+  final core::int i = core::int::parse(args.{core::List::[]}(0){(core::int) → core::String});
+  self::testAndroid(i);
+  self::testFuchsia(i);
+  self::testIOS(i);
+  self::testLinux(i);
+  self::testMacOS(i);
+  self::testWindows(i);
+  self::testSwitchStatements(i);
+  self::testPragma(i);
+  self::debugDefaultTestPlatform = #C3;
+  self::testConditionalPragma(i);
+  self::testConditionalPragmaWithAsserts(i);
+}
+constants  {
+  #C1 = 0
+  #C2 = "android"
+  #C3 = self::TestPlatform {index:#C1, _name:#C2}
+  #C4 = 1
+  #C5 = "fuchsia"
+  #C6 = self::TestPlatform {index:#C4, _name:#C5}
+  #C7 = 2
+  #C8 = "ios"
+  #C9 = self::TestPlatform {index:#C7, _name:#C8}
+  #C10 = 3
+  #C11 = "linux"
+  #C12 = self::TestPlatform {index:#C10, _name:#C11}
+  #C13 = 4
+  #C14 = "macos"
+  #C15 = self::TestPlatform {index:#C13, _name:#C14}
+  #C16 = 5
+  #C17 = "windows"
+  #C18 = self::TestPlatform {index:#C16, _name:#C17}
+  #C19 = <self::TestPlatform>[#C3, #C6, #C9, #C12, #C15, #C18]
+  #C20 = true
+  #C21 = false
+  #C22 = "/"
+  #C23 = "vm:platform-const"
+  #C24 = null
+  #C25 = core::pragma {name:#C23, options:#C24}
+  #C26 = "vm:platform-const-if"
+  #C27 = core::pragma {name:#C26, options:#C21}
+}
diff --git a/pkg/vm/testcases/transformations/vm_constant_evaluator/platform_testcases.dart.fuchsia.expect b/pkg/vm/testcases/transformations/vm_constant_evaluator/platform_testcases.dart.fuchsia.expect
index b95d833..2147848 100644
--- a/pkg/vm/testcases/transformations/vm_constant_evaluator/platform_testcases.dart.fuchsia.expect
+++ b/pkg/vm/testcases/transformations/vm_constant_evaluator/platform_testcases.dart.fuchsia.expect
@@ -18,6 +18,9 @@
   method _enumToString() → core::String
     return "TestPlatform.${this.{core::_Enum::_name}{core::String}}";
 }
+static const field core::bool kDebugMode = #C20;
+static field self::TestPlatform? debugDefaultTestPlatform;
+static const field core::bool enableAsserts = #C20;
 static method testAndroid(core::int i) → void {
   final core::bool b = #C20;
   core::print(b);
@@ -58,7 +61,7 @@
 @#C25
 static get defaultTestPlatform() → self::TestPlatform {
   return #C6;
-  throw "Unexpected platform";
+  throw "Unexpected platform: ${#C5}";
 }
 static method testPragma(core::int i) → void {
   core::print(#C6);
@@ -68,6 +71,38 @@
     break #L2;
   }
 }
+@#C27
+static get defaultTestPlatformOverridableWhenDebug() → self::TestPlatform {
+  late self::TestPlatform result;
+  {
+    result = #C6;
+  }
+  return result;
+}
+static method testConditionalPragma(core::int i) → void {
+  core::print(#C6);
+  #L3:
+  {
+    core::print("is fuchsia");
+    break #L3;
+  }
+}
+@#C27
+static get defaultTestPlatformOverridableWithAsserts() → self::TestPlatform {
+  late self::TestPlatform result;
+  {
+    result = #C6;
+  }
+  return result;
+}
+static method testConditionalPragmaWithAsserts(core::int i) → void {
+  core::print(#C6);
+  #L4:
+  {
+    core::print("is fuchsia");
+    break #L4;
+  }
+}
 static method main(core::List<core::String> args) → dynamic {
   if(args.{core::Iterable::isEmpty}{core::bool})
     return;
@@ -80,6 +115,9 @@
   self::testWindows(i);
   self::testSwitchStatements(i);
   self::testPragma(i);
+  self::debugDefaultTestPlatform = #C3;
+  self::testConditionalPragma(i);
+  self::testConditionalPragmaWithAsserts(i);
 }
 constants  {
   #C1 = 0
@@ -107,4 +145,6 @@
   #C23 = "vm:platform-const"
   #C24 = null
   #C25 = core::pragma {name:#C23, options:#C24}
+  #C26 = "vm:platform-const-if"
+  #C27 = core::pragma {name:#C26, options:#C21}
 }
diff --git a/pkg/vm/testcases/transformations/vm_constant_evaluator/platform_testcases.dart.fuchsia.withAsserts.expect b/pkg/vm/testcases/transformations/vm_constant_evaluator/platform_testcases.dart.fuchsia.withAsserts.expect
new file mode 100644
index 0000000..8cbcf60
--- /dev/null
+++ b/pkg/vm/testcases/transformations/vm_constant_evaluator/platform_testcases.dart.fuchsia.withAsserts.expect
@@ -0,0 +1,192 @@
+library #lib;
+import self as self;
+import "dart:core" as core;
+import "dart:io" as io;
+
+import "dart:io";
+
+class TestPlatform extends core::_Enum /*isEnum*/  {
+  static const field core::List<self::TestPlatform> values = #C19;
+  enum-element static const field self::TestPlatform android = #C3;
+  enum-element static const field self::TestPlatform fuchsia = #C6;
+  enum-element static const field self::TestPlatform ios = #C9;
+  enum-element static const field self::TestPlatform linux = #C12;
+  enum-element static const field self::TestPlatform macos = #C15;
+  enum-element static const field self::TestPlatform windows = #C18;
+  const synthetic constructor •(core::int #index, core::String #name) → self::TestPlatform
+    : super core::_Enum::•(#index, #name)
+    ;
+  method _enumToString() → core::String
+    return "TestPlatform.${this.{core::_Enum::_name}{core::String}}";
+}
+static const field core::bool kDebugMode = #C20;
+static field self::TestPlatform? debugDefaultTestPlatform;
+static const field core::bool enableAsserts = #C21;
+static method testAndroid(core::int i) → void {
+  final core::bool b = #C20;
+  core::print(b);
+}
+static method testFuchsia(core::int i) → void {
+  final core::bool b = #C21;
+  core::print(b);
+  {
+    final core::String os = #C5;
+    core::print(os);
+    final core::String sep = #C22;
+    core::print(sep);
+  }
+}
+static method testIOS(core::int i) → void {
+  final core::bool b = #C20;
+  core::print(b);
+}
+static method testLinux(core::int i) → void {
+  final core::bool b = #C20;
+  core::print(b);
+}
+static method testMacOS(core::int i) → void {
+  final core::bool b = #C20;
+  core::print(b);
+}
+static method testWindows(core::int i) → void {
+  final core::bool b = #C20;
+  core::print(b);
+}
+static method testSwitchStatements(core::int i) → void {
+  #L1:
+  {
+    core::print("is fuchsia");
+    break #L1;
+  }
+}
+@#C25
+static get defaultTestPlatform() → self::TestPlatform {
+  return #C6;
+  throw "Unexpected platform: ${#C5}";
+}
+static method testPragma(core::int i) → void {
+  core::print(#C6);
+  #L2:
+  {
+    core::print("is fuchsia");
+    break #L2;
+  }
+}
+@#C27
+static get defaultTestPlatformOverridableWhenDebug() → self::TestPlatform {
+  late self::TestPlatform result;
+  {
+    result = #C6;
+  }
+  return result;
+}
+static method testConditionalPragma(core::int i) → void {
+  core::print(#C6);
+  #L3:
+  {
+    core::print("is fuchsia");
+    break #L3;
+  }
+}
+@#C28
+static get defaultTestPlatformOverridableWithAsserts() → self::TestPlatform {
+  late self::TestPlatform result;
+  {
+    result = #C6;
+  }
+  assert((() → core::bool {
+    if(io::Platform::environment.{core::Map::containsKey}("FLUTTER_TEST"){(core::Object?) → core::bool}) {
+      result = #C3;
+    }
+    return true;
+  })(){() → core::bool});
+  return result;
+}
+static method testConditionalPragmaWithAsserts(core::int i) → void {
+  core::print(self::defaultTestPlatformOverridableWithAsserts);
+  #L4:
+  switch(self::defaultTestPlatformOverridableWithAsserts) /* isExplicitlyExhaustive, self::TestPlatform */ {
+    #L5:
+    case #C3:
+      {
+        core::print("is android");
+        break #L4;
+      }
+    #L6:
+    case #C6:
+      {
+        core::print("is fuchsia");
+        break #L4;
+      }
+    #L7:
+    case #C9:
+      {
+        core::print("is ios");
+        break #L4;
+      }
+    #L8:
+    case #C12:
+      {
+        core::print("is linux");
+        break #L4;
+      }
+    #L9:
+    case #C15:
+      {
+        core::print("is macos");
+        break #L4;
+      }
+    #L10:
+    case #C18:
+      {
+        core::print("is windows");
+        break #L4;
+      }
+  }
+}
+static method main(core::List<core::String> args) → dynamic {
+  if(args.{core::Iterable::isEmpty}{core::bool})
+    return;
+  final core::int i = core::int::parse(args.{core::List::[]}(0){(core::int) → core::String});
+  self::testAndroid(i);
+  self::testFuchsia(i);
+  self::testIOS(i);
+  self::testLinux(i);
+  self::testMacOS(i);
+  self::testWindows(i);
+  self::testSwitchStatements(i);
+  self::testPragma(i);
+  self::debugDefaultTestPlatform = #C3;
+  self::testConditionalPragma(i);
+  self::testConditionalPragmaWithAsserts(i);
+}
+constants  {
+  #C1 = 0
+  #C2 = "android"
+  #C3 = self::TestPlatform {index:#C1, _name:#C2}
+  #C4 = 1
+  #C5 = "fuchsia"
+  #C6 = self::TestPlatform {index:#C4, _name:#C5}
+  #C7 = 2
+  #C8 = "ios"
+  #C9 = self::TestPlatform {index:#C7, _name:#C8}
+  #C10 = 3
+  #C11 = "linux"
+  #C12 = self::TestPlatform {index:#C10, _name:#C11}
+  #C13 = 4
+  #C14 = "macos"
+  #C15 = self::TestPlatform {index:#C13, _name:#C14}
+  #C16 = 5
+  #C17 = "windows"
+  #C18 = self::TestPlatform {index:#C16, _name:#C17}
+  #C19 = <self::TestPlatform>[#C3, #C6, #C9, #C12, #C15, #C18]
+  #C20 = false
+  #C21 = true
+  #C22 = "/"
+  #C23 = "vm:platform-const"
+  #C24 = null
+  #C25 = core::pragma {name:#C23, options:#C24}
+  #C26 = "vm:platform-const-if"
+  #C27 = core::pragma {name:#C26, options:#C21}
+  #C28 = core::pragma {name:#C26, options:#C20}
+}
diff --git a/pkg/vm/testcases/transformations/vm_constant_evaluator/platform_testcases.dart.ios.debug.expect b/pkg/vm/testcases/transformations/vm_constant_evaluator/platform_testcases.dart.ios.debug.expect
new file mode 100644
index 0000000..46d1024
--- /dev/null
+++ b/pkg/vm/testcases/transformations/vm_constant_evaluator/platform_testcases.dart.ios.debug.expect
@@ -0,0 +1,188 @@
+library #lib;
+import self as self;
+import "dart:core" as core;
+
+import "dart:io";
+
+class TestPlatform extends core::_Enum /*isEnum*/  {
+  static const field core::List<self::TestPlatform> values = #C19;
+  enum-element static const field self::TestPlatform android = #C3;
+  enum-element static const field self::TestPlatform fuchsia = #C6;
+  enum-element static const field self::TestPlatform ios = #C9;
+  enum-element static const field self::TestPlatform linux = #C12;
+  enum-element static const field self::TestPlatform macos = #C15;
+  enum-element static const field self::TestPlatform windows = #C18;
+  const synthetic constructor •(core::int #index, core::String #name) → self::TestPlatform
+    : super core::_Enum::•(#index, #name)
+    ;
+  method _enumToString() → core::String
+    return "TestPlatform.${this.{core::_Enum::_name}{core::String}}";
+}
+static const field core::bool kDebugMode = #C20;
+static field self::TestPlatform? debugDefaultTestPlatform;
+static const field core::bool enableAsserts = #C21;
+static method testAndroid(core::int i) → void {
+  final core::bool b = #C21;
+  core::print(b);
+}
+static method testFuchsia(core::int i) → void {
+  final core::bool b = #C21;
+  core::print(b);
+}
+static method testIOS(core::int i) → void {
+  final core::bool b = #C20;
+  core::print(b);
+  {
+    final core::String os = #C8;
+    core::print(os);
+    final core::String sep = #C22;
+    core::print(sep);
+  }
+}
+static method testLinux(core::int i) → void {
+  final core::bool b = #C21;
+  core::print(b);
+}
+static method testMacOS(core::int i) → void {
+  final core::bool b = #C21;
+  core::print(b);
+}
+static method testWindows(core::int i) → void {
+  final core::bool b = #C21;
+  core::print(b);
+}
+static method testSwitchStatements(core::int i) → void {
+  #L1:
+  {
+    core::print("is ios");
+    break #L1;
+  }
+}
+@#C25
+static get defaultTestPlatform() → self::TestPlatform {
+  return #C9;
+  throw "Unexpected platform: ${#C8}";
+}
+static method testPragma(core::int i) → void {
+  core::print(#C9);
+  #L2:
+  {
+    core::print("is ios");
+    break #L2;
+  }
+}
+@#C27
+static get defaultTestPlatformOverridableWhenDebug() → self::TestPlatform {
+  late self::TestPlatform result;
+  {
+    result = #C9;
+  }
+  if(!(self::debugDefaultTestPlatform == null)) {
+    result = self::debugDefaultTestPlatform!;
+  }
+  return result;
+}
+static method testConditionalPragma(core::int i) → void {
+  core::print(self::defaultTestPlatformOverridableWhenDebug);
+  #L3:
+  switch(self::defaultTestPlatformOverridableWhenDebug) /* isExplicitlyExhaustive, self::TestPlatform */ {
+    #L4:
+    case #C3:
+      {
+        core::print("is android");
+        break #L3;
+      }
+    #L5:
+    case #C6:
+      {
+        core::print("is fuchsia");
+        break #L3;
+      }
+    #L6:
+    case #C9:
+      {
+        core::print("is ios");
+        break #L3;
+      }
+    #L7:
+    case #C12:
+      {
+        core::print("is linux");
+        break #L3;
+      }
+    #L8:
+    case #C15:
+      {
+        core::print("is macos");
+        break #L3;
+      }
+    #L9:
+    case #C18:
+      {
+        core::print("is windows");
+        break #L3;
+      }
+  }
+}
+@#C28
+static get defaultTestPlatformOverridableWithAsserts() → self::TestPlatform {
+  late self::TestPlatform result;
+  {
+    result = #C9;
+  }
+  return result;
+}
+static method testConditionalPragmaWithAsserts(core::int i) → void {
+  core::print(#C9);
+  #L10:
+  {
+    core::print("is ios");
+    break #L10;
+  }
+}
+static method main(core::List<core::String> args) → dynamic {
+  if(args.{core::Iterable::isEmpty}{core::bool})
+    return;
+  final core::int i = core::int::parse(args.{core::List::[]}(0){(core::int) → core::String});
+  self::testAndroid(i);
+  self::testFuchsia(i);
+  self::testIOS(i);
+  self::testLinux(i);
+  self::testMacOS(i);
+  self::testWindows(i);
+  self::testSwitchStatements(i);
+  self::testPragma(i);
+  self::debugDefaultTestPlatform = #C3;
+  self::testConditionalPragma(i);
+  self::testConditionalPragmaWithAsserts(i);
+}
+constants  {
+  #C1 = 0
+  #C2 = "android"
+  #C3 = self::TestPlatform {index:#C1, _name:#C2}
+  #C4 = 1
+  #C5 = "fuchsia"
+  #C6 = self::TestPlatform {index:#C4, _name:#C5}
+  #C7 = 2
+  #C8 = "ios"
+  #C9 = self::TestPlatform {index:#C7, _name:#C8}
+  #C10 = 3
+  #C11 = "linux"
+  #C12 = self::TestPlatform {index:#C10, _name:#C11}
+  #C13 = 4
+  #C14 = "macos"
+  #C15 = self::TestPlatform {index:#C13, _name:#C14}
+  #C16 = 5
+  #C17 = "windows"
+  #C18 = self::TestPlatform {index:#C16, _name:#C17}
+  #C19 = <self::TestPlatform>[#C3, #C6, #C9, #C12, #C15, #C18]
+  #C20 = true
+  #C21 = false
+  #C22 = "/"
+  #C23 = "vm:platform-const"
+  #C24 = null
+  #C25 = core::pragma {name:#C23, options:#C24}
+  #C26 = "vm:platform-const-if"
+  #C27 = core::pragma {name:#C26, options:#C21}
+  #C28 = core::pragma {name:#C26, options:#C20}
+}
diff --git a/pkg/vm/testcases/transformations/vm_constant_evaluator/platform_testcases.dart.ios.debug.withAsserts.expect b/pkg/vm/testcases/transformations/vm_constant_evaluator/platform_testcases.dart.ios.debug.withAsserts.expect
new file mode 100644
index 0000000..b68e690
--- /dev/null
+++ b/pkg/vm/testcases/transformations/vm_constant_evaluator/platform_testcases.dart.ios.debug.withAsserts.expect
@@ -0,0 +1,228 @@
+library #lib;
+import self as self;
+import "dart:core" as core;
+import "dart:io" as io;
+
+import "dart:io";
+
+class TestPlatform extends core::_Enum /*isEnum*/  {
+  static const field core::List<self::TestPlatform> values = #C19;
+  enum-element static const field self::TestPlatform android = #C3;
+  enum-element static const field self::TestPlatform fuchsia = #C6;
+  enum-element static const field self::TestPlatform ios = #C9;
+  enum-element static const field self::TestPlatform linux = #C12;
+  enum-element static const field self::TestPlatform macos = #C15;
+  enum-element static const field self::TestPlatform windows = #C18;
+  const synthetic constructor •(core::int #index, core::String #name) → self::TestPlatform
+    : super core::_Enum::•(#index, #name)
+    ;
+  method _enumToString() → core::String
+    return "TestPlatform.${this.{core::_Enum::_name}{core::String}}";
+}
+static const field core::bool kDebugMode = #C20;
+static field self::TestPlatform? debugDefaultTestPlatform;
+static const field core::bool enableAsserts = #C20;
+static method testAndroid(core::int i) → void {
+  final core::bool b = #C21;
+  core::print(b);
+}
+static method testFuchsia(core::int i) → void {
+  final core::bool b = #C21;
+  core::print(b);
+}
+static method testIOS(core::int i) → void {
+  final core::bool b = #C20;
+  core::print(b);
+  {
+    final core::String os = #C8;
+    core::print(os);
+    final core::String sep = #C22;
+    core::print(sep);
+  }
+}
+static method testLinux(core::int i) → void {
+  final core::bool b = #C21;
+  core::print(b);
+}
+static method testMacOS(core::int i) → void {
+  final core::bool b = #C21;
+  core::print(b);
+}
+static method testWindows(core::int i) → void {
+  final core::bool b = #C21;
+  core::print(b);
+}
+static method testSwitchStatements(core::int i) → void {
+  #L1:
+  {
+    core::print("is ios");
+    break #L1;
+  }
+}
+@#C25
+static get defaultTestPlatform() → self::TestPlatform {
+  return #C9;
+  throw "Unexpected platform: ${#C8}";
+}
+static method testPragma(core::int i) → void {
+  core::print(#C9);
+  #L2:
+  {
+    core::print("is ios");
+    break #L2;
+  }
+}
+@#C27
+static get defaultTestPlatformOverridableWhenDebug() → self::TestPlatform {
+  late self::TestPlatform result;
+  {
+    result = #C9;
+  }
+  if(!(self::debugDefaultTestPlatform == null)) {
+    result = self::debugDefaultTestPlatform!;
+  }
+  return result;
+}
+static method testConditionalPragma(core::int i) → void {
+  core::print(self::defaultTestPlatformOverridableWhenDebug);
+  #L3:
+  switch(self::defaultTestPlatformOverridableWhenDebug) /* isExplicitlyExhaustive, self::TestPlatform */ {
+    #L4:
+    case #C3:
+      {
+        core::print("is android");
+        break #L3;
+      }
+    #L5:
+    case #C6:
+      {
+        core::print("is fuchsia");
+        break #L3;
+      }
+    #L6:
+    case #C9:
+      {
+        core::print("is ios");
+        break #L3;
+      }
+    #L7:
+    case #C12:
+      {
+        core::print("is linux");
+        break #L3;
+      }
+    #L8:
+    case #C15:
+      {
+        core::print("is macos");
+        break #L3;
+      }
+    #L9:
+    case #C18:
+      {
+        core::print("is windows");
+        break #L3;
+      }
+  }
+}
+@#C27
+static get defaultTestPlatformOverridableWithAsserts() → self::TestPlatform {
+  late self::TestPlatform result;
+  {
+    result = #C9;
+  }
+  assert((() → core::bool {
+    if(io::Platform::environment.{core::Map::containsKey}("FLUTTER_TEST"){(core::Object?) → core::bool}) {
+      result = #C3;
+    }
+    return true;
+  })(){() → core::bool});
+  return result;
+}
+static method testConditionalPragmaWithAsserts(core::int i) → void {
+  core::print(self::defaultTestPlatformOverridableWithAsserts);
+  #L10:
+  switch(self::defaultTestPlatformOverridableWithAsserts) /* isExplicitlyExhaustive, self::TestPlatform */ {
+    #L11:
+    case #C3:
+      {
+        core::print("is android");
+        break #L10;
+      }
+    #L12:
+    case #C6:
+      {
+        core::print("is fuchsia");
+        break #L10;
+      }
+    #L13:
+    case #C9:
+      {
+        core::print("is ios");
+        break #L10;
+      }
+    #L14:
+    case #C12:
+      {
+        core::print("is linux");
+        break #L10;
+      }
+    #L15:
+    case #C15:
+      {
+        core::print("is macos");
+        break #L10;
+      }
+    #L16:
+    case #C18:
+      {
+        core::print("is windows");
+        break #L10;
+      }
+  }
+}
+static method main(core::List<core::String> args) → dynamic {
+  if(args.{core::Iterable::isEmpty}{core::bool})
+    return;
+  final core::int i = core::int::parse(args.{core::List::[]}(0){(core::int) → core::String});
+  self::testAndroid(i);
+  self::testFuchsia(i);
+  self::testIOS(i);
+  self::testLinux(i);
+  self::testMacOS(i);
+  self::testWindows(i);
+  self::testSwitchStatements(i);
+  self::testPragma(i);
+  self::debugDefaultTestPlatform = #C3;
+  self::testConditionalPragma(i);
+  self::testConditionalPragmaWithAsserts(i);
+}
+constants  {
+  #C1 = 0
+  #C2 = "android"
+  #C3 = self::TestPlatform {index:#C1, _name:#C2}
+  #C4 = 1
+  #C5 = "fuchsia"
+  #C6 = self::TestPlatform {index:#C4, _name:#C5}
+  #C7 = 2
+  #C8 = "ios"
+  #C9 = self::TestPlatform {index:#C7, _name:#C8}
+  #C10 = 3
+  #C11 = "linux"
+  #C12 = self::TestPlatform {index:#C10, _name:#C11}
+  #C13 = 4
+  #C14 = "macos"
+  #C15 = self::TestPlatform {index:#C13, _name:#C14}
+  #C16 = 5
+  #C17 = "windows"
+  #C18 = self::TestPlatform {index:#C16, _name:#C17}
+  #C19 = <self::TestPlatform>[#C3, #C6, #C9, #C12, #C15, #C18]
+  #C20 = true
+  #C21 = false
+  #C22 = "/"
+  #C23 = "vm:platform-const"
+  #C24 = null
+  #C25 = core::pragma {name:#C23, options:#C24}
+  #C26 = "vm:platform-const-if"
+  #C27 = core::pragma {name:#C26, options:#C21}
+}
diff --git a/pkg/vm/testcases/transformations/vm_constant_evaluator/platform_testcases.dart.ios.expect b/pkg/vm/testcases/transformations/vm_constant_evaluator/platform_testcases.dart.ios.expect
index 21c480b..3573806 100644
--- a/pkg/vm/testcases/transformations/vm_constant_evaluator/platform_testcases.dart.ios.expect
+++ b/pkg/vm/testcases/transformations/vm_constant_evaluator/platform_testcases.dart.ios.expect
@@ -18,6 +18,9 @@
   method _enumToString() → core::String
     return "TestPlatform.${this.{core::_Enum::_name}{core::String}}";
 }
+static const field core::bool kDebugMode = #C20;
+static field self::TestPlatform? debugDefaultTestPlatform;
+static const field core::bool enableAsserts = #C20;
 static method testAndroid(core::int i) → void {
   final core::bool b = #C20;
   core::print(b);
@@ -58,7 +61,7 @@
 @#C25
 static get defaultTestPlatform() → self::TestPlatform {
   return #C9;
-  throw "Unexpected platform";
+  throw "Unexpected platform: ${#C8}";
 }
 static method testPragma(core::int i) → void {
   core::print(#C9);
@@ -68,6 +71,38 @@
     break #L2;
   }
 }
+@#C27
+static get defaultTestPlatformOverridableWhenDebug() → self::TestPlatform {
+  late self::TestPlatform result;
+  {
+    result = #C9;
+  }
+  return result;
+}
+static method testConditionalPragma(core::int i) → void {
+  core::print(#C9);
+  #L3:
+  {
+    core::print("is ios");
+    break #L3;
+  }
+}
+@#C27
+static get defaultTestPlatformOverridableWithAsserts() → self::TestPlatform {
+  late self::TestPlatform result;
+  {
+    result = #C9;
+  }
+  return result;
+}
+static method testConditionalPragmaWithAsserts(core::int i) → void {
+  core::print(#C9);
+  #L4:
+  {
+    core::print("is ios");
+    break #L4;
+  }
+}
 static method main(core::List<core::String> args) → dynamic {
   if(args.{core::Iterable::isEmpty}{core::bool})
     return;
@@ -80,6 +115,9 @@
   self::testWindows(i);
   self::testSwitchStatements(i);
   self::testPragma(i);
+  self::debugDefaultTestPlatform = #C3;
+  self::testConditionalPragma(i);
+  self::testConditionalPragmaWithAsserts(i);
 }
 constants  {
   #C1 = 0
@@ -107,4 +145,6 @@
   #C23 = "vm:platform-const"
   #C24 = null
   #C25 = core::pragma {name:#C23, options:#C24}
+  #C26 = "vm:platform-const-if"
+  #C27 = core::pragma {name:#C26, options:#C21}
 }
diff --git a/pkg/vm/testcases/transformations/vm_constant_evaluator/platform_testcases.dart.ios.withAsserts.expect b/pkg/vm/testcases/transformations/vm_constant_evaluator/platform_testcases.dart.ios.withAsserts.expect
new file mode 100644
index 0000000..db02a83
--- /dev/null
+++ b/pkg/vm/testcases/transformations/vm_constant_evaluator/platform_testcases.dart.ios.withAsserts.expect
@@ -0,0 +1,192 @@
+library #lib;
+import self as self;
+import "dart:core" as core;
+import "dart:io" as io;
+
+import "dart:io";
+
+class TestPlatform extends core::_Enum /*isEnum*/  {
+  static const field core::List<self::TestPlatform> values = #C19;
+  enum-element static const field self::TestPlatform android = #C3;
+  enum-element static const field self::TestPlatform fuchsia = #C6;
+  enum-element static const field self::TestPlatform ios = #C9;
+  enum-element static const field self::TestPlatform linux = #C12;
+  enum-element static const field self::TestPlatform macos = #C15;
+  enum-element static const field self::TestPlatform windows = #C18;
+  const synthetic constructor •(core::int #index, core::String #name) → self::TestPlatform
+    : super core::_Enum::•(#index, #name)
+    ;
+  method _enumToString() → core::String
+    return "TestPlatform.${this.{core::_Enum::_name}{core::String}}";
+}
+static const field core::bool kDebugMode = #C20;
+static field self::TestPlatform? debugDefaultTestPlatform;
+static const field core::bool enableAsserts = #C21;
+static method testAndroid(core::int i) → void {
+  final core::bool b = #C20;
+  core::print(b);
+}
+static method testFuchsia(core::int i) → void {
+  final core::bool b = #C20;
+  core::print(b);
+}
+static method testIOS(core::int i) → void {
+  final core::bool b = #C21;
+  core::print(b);
+  {
+    final core::String os = #C8;
+    core::print(os);
+    final core::String sep = #C22;
+    core::print(sep);
+  }
+}
+static method testLinux(core::int i) → void {
+  final core::bool b = #C20;
+  core::print(b);
+}
+static method testMacOS(core::int i) → void {
+  final core::bool b = #C20;
+  core::print(b);
+}
+static method testWindows(core::int i) → void {
+  final core::bool b = #C20;
+  core::print(b);
+}
+static method testSwitchStatements(core::int i) → void {
+  #L1:
+  {
+    core::print("is ios");
+    break #L1;
+  }
+}
+@#C25
+static get defaultTestPlatform() → self::TestPlatform {
+  return #C9;
+  throw "Unexpected platform: ${#C8}";
+}
+static method testPragma(core::int i) → void {
+  core::print(#C9);
+  #L2:
+  {
+    core::print("is ios");
+    break #L2;
+  }
+}
+@#C27
+static get defaultTestPlatformOverridableWhenDebug() → self::TestPlatform {
+  late self::TestPlatform result;
+  {
+    result = #C9;
+  }
+  return result;
+}
+static method testConditionalPragma(core::int i) → void {
+  core::print(#C9);
+  #L3:
+  {
+    core::print("is ios");
+    break #L3;
+  }
+}
+@#C28
+static get defaultTestPlatformOverridableWithAsserts() → self::TestPlatform {
+  late self::TestPlatform result;
+  {
+    result = #C9;
+  }
+  assert((() → core::bool {
+    if(io::Platform::environment.{core::Map::containsKey}("FLUTTER_TEST"){(core::Object?) → core::bool}) {
+      result = #C3;
+    }
+    return true;
+  })(){() → core::bool});
+  return result;
+}
+static method testConditionalPragmaWithAsserts(core::int i) → void {
+  core::print(self::defaultTestPlatformOverridableWithAsserts);
+  #L4:
+  switch(self::defaultTestPlatformOverridableWithAsserts) /* isExplicitlyExhaustive, self::TestPlatform */ {
+    #L5:
+    case #C3:
+      {
+        core::print("is android");
+        break #L4;
+      }
+    #L6:
+    case #C6:
+      {
+        core::print("is fuchsia");
+        break #L4;
+      }
+    #L7:
+    case #C9:
+      {
+        core::print("is ios");
+        break #L4;
+      }
+    #L8:
+    case #C12:
+      {
+        core::print("is linux");
+        break #L4;
+      }
+    #L9:
+    case #C15:
+      {
+        core::print("is macos");
+        break #L4;
+      }
+    #L10:
+    case #C18:
+      {
+        core::print("is windows");
+        break #L4;
+      }
+  }
+}
+static method main(core::List<core::String> args) → dynamic {
+  if(args.{core::Iterable::isEmpty}{core::bool})
+    return;
+  final core::int i = core::int::parse(args.{core::List::[]}(0){(core::int) → core::String});
+  self::testAndroid(i);
+  self::testFuchsia(i);
+  self::testIOS(i);
+  self::testLinux(i);
+  self::testMacOS(i);
+  self::testWindows(i);
+  self::testSwitchStatements(i);
+  self::testPragma(i);
+  self::debugDefaultTestPlatform = #C3;
+  self::testConditionalPragma(i);
+  self::testConditionalPragmaWithAsserts(i);
+}
+constants  {
+  #C1 = 0
+  #C2 = "android"
+  #C3 = self::TestPlatform {index:#C1, _name:#C2}
+  #C4 = 1
+  #C5 = "fuchsia"
+  #C6 = self::TestPlatform {index:#C4, _name:#C5}
+  #C7 = 2
+  #C8 = "ios"
+  #C9 = self::TestPlatform {index:#C7, _name:#C8}
+  #C10 = 3
+  #C11 = "linux"
+  #C12 = self::TestPlatform {index:#C10, _name:#C11}
+  #C13 = 4
+  #C14 = "macos"
+  #C15 = self::TestPlatform {index:#C13, _name:#C14}
+  #C16 = 5
+  #C17 = "windows"
+  #C18 = self::TestPlatform {index:#C16, _name:#C17}
+  #C19 = <self::TestPlatform>[#C3, #C6, #C9, #C12, #C15, #C18]
+  #C20 = false
+  #C21 = true
+  #C22 = "/"
+  #C23 = "vm:platform-const"
+  #C24 = null
+  #C25 = core::pragma {name:#C23, options:#C24}
+  #C26 = "vm:platform-const-if"
+  #C27 = core::pragma {name:#C26, options:#C21}
+  #C28 = core::pragma {name:#C26, options:#C20}
+}
diff --git a/pkg/vm/testcases/transformations/vm_constant_evaluator/platform_testcases.dart.linux.debug.expect b/pkg/vm/testcases/transformations/vm_constant_evaluator/platform_testcases.dart.linux.debug.expect
new file mode 100644
index 0000000..875821e
--- /dev/null
+++ b/pkg/vm/testcases/transformations/vm_constant_evaluator/platform_testcases.dart.linux.debug.expect
@@ -0,0 +1,188 @@
+library #lib;
+import self as self;
+import "dart:core" as core;
+
+import "dart:io";
+
+class TestPlatform extends core::_Enum /*isEnum*/  {
+  static const field core::List<self::TestPlatform> values = #C19;
+  enum-element static const field self::TestPlatform android = #C3;
+  enum-element static const field self::TestPlatform fuchsia = #C6;
+  enum-element static const field self::TestPlatform ios = #C9;
+  enum-element static const field self::TestPlatform linux = #C12;
+  enum-element static const field self::TestPlatform macos = #C15;
+  enum-element static const field self::TestPlatform windows = #C18;
+  const synthetic constructor •(core::int #index, core::String #name) → self::TestPlatform
+    : super core::_Enum::•(#index, #name)
+    ;
+  method _enumToString() → core::String
+    return "TestPlatform.${this.{core::_Enum::_name}{core::String}}";
+}
+static const field core::bool kDebugMode = #C20;
+static field self::TestPlatform? debugDefaultTestPlatform;
+static const field core::bool enableAsserts = #C21;
+static method testAndroid(core::int i) → void {
+  final core::bool b = #C21;
+  core::print(b);
+}
+static method testFuchsia(core::int i) → void {
+  final core::bool b = #C21;
+  core::print(b);
+}
+static method testIOS(core::int i) → void {
+  final core::bool b = #C21;
+  core::print(b);
+}
+static method testLinux(core::int i) → void {
+  final core::bool b = #C20;
+  core::print(b);
+  {
+    final core::String os = #C11;
+    core::print(os);
+    final core::String sep = #C22;
+    core::print(sep);
+  }
+}
+static method testMacOS(core::int i) → void {
+  final core::bool b = #C21;
+  core::print(b);
+}
+static method testWindows(core::int i) → void {
+  final core::bool b = #C21;
+  core::print(b);
+}
+static method testSwitchStatements(core::int i) → void {
+  #L1:
+  {
+    core::print("is linux");
+    break #L1;
+  }
+}
+@#C25
+static get defaultTestPlatform() → self::TestPlatform {
+  return #C12;
+  throw "Unexpected platform: ${#C11}";
+}
+static method testPragma(core::int i) → void {
+  core::print(#C12);
+  #L2:
+  {
+    core::print("is linux");
+    break #L2;
+  }
+}
+@#C27
+static get defaultTestPlatformOverridableWhenDebug() → self::TestPlatform {
+  late self::TestPlatform result;
+  {
+    result = #C12;
+  }
+  if(!(self::debugDefaultTestPlatform == null)) {
+    result = self::debugDefaultTestPlatform!;
+  }
+  return result;
+}
+static method testConditionalPragma(core::int i) → void {
+  core::print(self::defaultTestPlatformOverridableWhenDebug);
+  #L3:
+  switch(self::defaultTestPlatformOverridableWhenDebug) /* isExplicitlyExhaustive, self::TestPlatform */ {
+    #L4:
+    case #C3:
+      {
+        core::print("is android");
+        break #L3;
+      }
+    #L5:
+    case #C6:
+      {
+        core::print("is fuchsia");
+        break #L3;
+      }
+    #L6:
+    case #C9:
+      {
+        core::print("is ios");
+        break #L3;
+      }
+    #L7:
+    case #C12:
+      {
+        core::print("is linux");
+        break #L3;
+      }
+    #L8:
+    case #C15:
+      {
+        core::print("is macos");
+        break #L3;
+      }
+    #L9:
+    case #C18:
+      {
+        core::print("is windows");
+        break #L3;
+      }
+  }
+}
+@#C28
+static get defaultTestPlatformOverridableWithAsserts() → self::TestPlatform {
+  late self::TestPlatform result;
+  {
+    result = #C12;
+  }
+  return result;
+}
+static method testConditionalPragmaWithAsserts(core::int i) → void {
+  core::print(#C12);
+  #L10:
+  {
+    core::print("is linux");
+    break #L10;
+  }
+}
+static method main(core::List<core::String> args) → dynamic {
+  if(args.{core::Iterable::isEmpty}{core::bool})
+    return;
+  final core::int i = core::int::parse(args.{core::List::[]}(0){(core::int) → core::String});
+  self::testAndroid(i);
+  self::testFuchsia(i);
+  self::testIOS(i);
+  self::testLinux(i);
+  self::testMacOS(i);
+  self::testWindows(i);
+  self::testSwitchStatements(i);
+  self::testPragma(i);
+  self::debugDefaultTestPlatform = #C3;
+  self::testConditionalPragma(i);
+  self::testConditionalPragmaWithAsserts(i);
+}
+constants  {
+  #C1 = 0
+  #C2 = "android"
+  #C3 = self::TestPlatform {index:#C1, _name:#C2}
+  #C4 = 1
+  #C5 = "fuchsia"
+  #C6 = self::TestPlatform {index:#C4, _name:#C5}
+  #C7 = 2
+  #C8 = "ios"
+  #C9 = self::TestPlatform {index:#C7, _name:#C8}
+  #C10 = 3
+  #C11 = "linux"
+  #C12 = self::TestPlatform {index:#C10, _name:#C11}
+  #C13 = 4
+  #C14 = "macos"
+  #C15 = self::TestPlatform {index:#C13, _name:#C14}
+  #C16 = 5
+  #C17 = "windows"
+  #C18 = self::TestPlatform {index:#C16, _name:#C17}
+  #C19 = <self::TestPlatform>[#C3, #C6, #C9, #C12, #C15, #C18]
+  #C20 = true
+  #C21 = false
+  #C22 = "/"
+  #C23 = "vm:platform-const"
+  #C24 = null
+  #C25 = core::pragma {name:#C23, options:#C24}
+  #C26 = "vm:platform-const-if"
+  #C27 = core::pragma {name:#C26, options:#C21}
+  #C28 = core::pragma {name:#C26, options:#C20}
+}
diff --git a/pkg/vm/testcases/transformations/vm_constant_evaluator/platform_testcases.dart.linux.debug.withAsserts.expect b/pkg/vm/testcases/transformations/vm_constant_evaluator/platform_testcases.dart.linux.debug.withAsserts.expect
new file mode 100644
index 0000000..16a9503
--- /dev/null
+++ b/pkg/vm/testcases/transformations/vm_constant_evaluator/platform_testcases.dart.linux.debug.withAsserts.expect
@@ -0,0 +1,228 @@
+library #lib;
+import self as self;
+import "dart:core" as core;
+import "dart:io" as io;
+
+import "dart:io";
+
+class TestPlatform extends core::_Enum /*isEnum*/  {
+  static const field core::List<self::TestPlatform> values = #C19;
+  enum-element static const field self::TestPlatform android = #C3;
+  enum-element static const field self::TestPlatform fuchsia = #C6;
+  enum-element static const field self::TestPlatform ios = #C9;
+  enum-element static const field self::TestPlatform linux = #C12;
+  enum-element static const field self::TestPlatform macos = #C15;
+  enum-element static const field self::TestPlatform windows = #C18;
+  const synthetic constructor •(core::int #index, core::String #name) → self::TestPlatform
+    : super core::_Enum::•(#index, #name)
+    ;
+  method _enumToString() → core::String
+    return "TestPlatform.${this.{core::_Enum::_name}{core::String}}";
+}
+static const field core::bool kDebugMode = #C20;
+static field self::TestPlatform? debugDefaultTestPlatform;
+static const field core::bool enableAsserts = #C20;
+static method testAndroid(core::int i) → void {
+  final core::bool b = #C21;
+  core::print(b);
+}
+static method testFuchsia(core::int i) → void {
+  final core::bool b = #C21;
+  core::print(b);
+}
+static method testIOS(core::int i) → void {
+  final core::bool b = #C21;
+  core::print(b);
+}
+static method testLinux(core::int i) → void {
+  final core::bool b = #C20;
+  core::print(b);
+  {
+    final core::String os = #C11;
+    core::print(os);
+    final core::String sep = #C22;
+    core::print(sep);
+  }
+}
+static method testMacOS(core::int i) → void {
+  final core::bool b = #C21;
+  core::print(b);
+}
+static method testWindows(core::int i) → void {
+  final core::bool b = #C21;
+  core::print(b);
+}
+static method testSwitchStatements(core::int i) → void {
+  #L1:
+  {
+    core::print("is linux");
+    break #L1;
+  }
+}
+@#C25
+static get defaultTestPlatform() → self::TestPlatform {
+  return #C12;
+  throw "Unexpected platform: ${#C11}";
+}
+static method testPragma(core::int i) → void {
+  core::print(#C12);
+  #L2:
+  {
+    core::print("is linux");
+    break #L2;
+  }
+}
+@#C27
+static get defaultTestPlatformOverridableWhenDebug() → self::TestPlatform {
+  late self::TestPlatform result;
+  {
+    result = #C12;
+  }
+  if(!(self::debugDefaultTestPlatform == null)) {
+    result = self::debugDefaultTestPlatform!;
+  }
+  return result;
+}
+static method testConditionalPragma(core::int i) → void {
+  core::print(self::defaultTestPlatformOverridableWhenDebug);
+  #L3:
+  switch(self::defaultTestPlatformOverridableWhenDebug) /* isExplicitlyExhaustive, self::TestPlatform */ {
+    #L4:
+    case #C3:
+      {
+        core::print("is android");
+        break #L3;
+      }
+    #L5:
+    case #C6:
+      {
+        core::print("is fuchsia");
+        break #L3;
+      }
+    #L6:
+    case #C9:
+      {
+        core::print("is ios");
+        break #L3;
+      }
+    #L7:
+    case #C12:
+      {
+        core::print("is linux");
+        break #L3;
+      }
+    #L8:
+    case #C15:
+      {
+        core::print("is macos");
+        break #L3;
+      }
+    #L9:
+    case #C18:
+      {
+        core::print("is windows");
+        break #L3;
+      }
+  }
+}
+@#C27
+static get defaultTestPlatformOverridableWithAsserts() → self::TestPlatform {
+  late self::TestPlatform result;
+  {
+    result = #C12;
+  }
+  assert((() → core::bool {
+    if(io::Platform::environment.{core::Map::containsKey}("FLUTTER_TEST"){(core::Object?) → core::bool}) {
+      result = #C3;
+    }
+    return true;
+  })(){() → core::bool});
+  return result;
+}
+static method testConditionalPragmaWithAsserts(core::int i) → void {
+  core::print(self::defaultTestPlatformOverridableWithAsserts);
+  #L10:
+  switch(self::defaultTestPlatformOverridableWithAsserts) /* isExplicitlyExhaustive, self::TestPlatform */ {
+    #L11:
+    case #C3:
+      {
+        core::print("is android");
+        break #L10;
+      }
+    #L12:
+    case #C6:
+      {
+        core::print("is fuchsia");
+        break #L10;
+      }
+    #L13:
+    case #C9:
+      {
+        core::print("is ios");
+        break #L10;
+      }
+    #L14:
+    case #C12:
+      {
+        core::print("is linux");
+        break #L10;
+      }
+    #L15:
+    case #C15:
+      {
+        core::print("is macos");
+        break #L10;
+      }
+    #L16:
+    case #C18:
+      {
+        core::print("is windows");
+        break #L10;
+      }
+  }
+}
+static method main(core::List<core::String> args) → dynamic {
+  if(args.{core::Iterable::isEmpty}{core::bool})
+    return;
+  final core::int i = core::int::parse(args.{core::List::[]}(0){(core::int) → core::String});
+  self::testAndroid(i);
+  self::testFuchsia(i);
+  self::testIOS(i);
+  self::testLinux(i);
+  self::testMacOS(i);
+  self::testWindows(i);
+  self::testSwitchStatements(i);
+  self::testPragma(i);
+  self::debugDefaultTestPlatform = #C3;
+  self::testConditionalPragma(i);
+  self::testConditionalPragmaWithAsserts(i);
+}
+constants  {
+  #C1 = 0
+  #C2 = "android"
+  #C3 = self::TestPlatform {index:#C1, _name:#C2}
+  #C4 = 1
+  #C5 = "fuchsia"
+  #C6 = self::TestPlatform {index:#C4, _name:#C5}
+  #C7 = 2
+  #C8 = "ios"
+  #C9 = self::TestPlatform {index:#C7, _name:#C8}
+  #C10 = 3
+  #C11 = "linux"
+  #C12 = self::TestPlatform {index:#C10, _name:#C11}
+  #C13 = 4
+  #C14 = "macos"
+  #C15 = self::TestPlatform {index:#C13, _name:#C14}
+  #C16 = 5
+  #C17 = "windows"
+  #C18 = self::TestPlatform {index:#C16, _name:#C17}
+  #C19 = <self::TestPlatform>[#C3, #C6, #C9, #C12, #C15, #C18]
+  #C20 = true
+  #C21 = false
+  #C22 = "/"
+  #C23 = "vm:platform-const"
+  #C24 = null
+  #C25 = core::pragma {name:#C23, options:#C24}
+  #C26 = "vm:platform-const-if"
+  #C27 = core::pragma {name:#C26, options:#C21}
+}
diff --git a/pkg/vm/testcases/transformations/vm_constant_evaluator/platform_testcases.dart.linux.expect b/pkg/vm/testcases/transformations/vm_constant_evaluator/platform_testcases.dart.linux.expect
index 95c3bbe..5b0f1d0 100644
--- a/pkg/vm/testcases/transformations/vm_constant_evaluator/platform_testcases.dart.linux.expect
+++ b/pkg/vm/testcases/transformations/vm_constant_evaluator/platform_testcases.dart.linux.expect
@@ -18,6 +18,9 @@
   method _enumToString() → core::String
     return "TestPlatform.${this.{core::_Enum::_name}{core::String}}";
 }
+static const field core::bool kDebugMode = #C20;
+static field self::TestPlatform? debugDefaultTestPlatform;
+static const field core::bool enableAsserts = #C20;
 static method testAndroid(core::int i) → void {
   final core::bool b = #C20;
   core::print(b);
@@ -58,7 +61,7 @@
 @#C25
 static get defaultTestPlatform() → self::TestPlatform {
   return #C12;
-  throw "Unexpected platform";
+  throw "Unexpected platform: ${#C11}";
 }
 static method testPragma(core::int i) → void {
   core::print(#C12);
@@ -68,6 +71,38 @@
     break #L2;
   }
 }
+@#C27
+static get defaultTestPlatformOverridableWhenDebug() → self::TestPlatform {
+  late self::TestPlatform result;
+  {
+    result = #C12;
+  }
+  return result;
+}
+static method testConditionalPragma(core::int i) → void {
+  core::print(#C12);
+  #L3:
+  {
+    core::print("is linux");
+    break #L3;
+  }
+}
+@#C27
+static get defaultTestPlatformOverridableWithAsserts() → self::TestPlatform {
+  late self::TestPlatform result;
+  {
+    result = #C12;
+  }
+  return result;
+}
+static method testConditionalPragmaWithAsserts(core::int i) → void {
+  core::print(#C12);
+  #L4:
+  {
+    core::print("is linux");
+    break #L4;
+  }
+}
 static method main(core::List<core::String> args) → dynamic {
   if(args.{core::Iterable::isEmpty}{core::bool})
     return;
@@ -80,6 +115,9 @@
   self::testWindows(i);
   self::testSwitchStatements(i);
   self::testPragma(i);
+  self::debugDefaultTestPlatform = #C3;
+  self::testConditionalPragma(i);
+  self::testConditionalPragmaWithAsserts(i);
 }
 constants  {
   #C1 = 0
@@ -107,4 +145,6 @@
   #C23 = "vm:platform-const"
   #C24 = null
   #C25 = core::pragma {name:#C23, options:#C24}
+  #C26 = "vm:platform-const-if"
+  #C27 = core::pragma {name:#C26, options:#C21}
 }
diff --git a/pkg/vm/testcases/transformations/vm_constant_evaluator/platform_testcases.dart.linux.withAsserts.expect b/pkg/vm/testcases/transformations/vm_constant_evaluator/platform_testcases.dart.linux.withAsserts.expect
new file mode 100644
index 0000000..1499db8
--- /dev/null
+++ b/pkg/vm/testcases/transformations/vm_constant_evaluator/platform_testcases.dart.linux.withAsserts.expect
@@ -0,0 +1,192 @@
+library #lib;
+import self as self;
+import "dart:core" as core;
+import "dart:io" as io;
+
+import "dart:io";
+
+class TestPlatform extends core::_Enum /*isEnum*/  {
+  static const field core::List<self::TestPlatform> values = #C19;
+  enum-element static const field self::TestPlatform android = #C3;
+  enum-element static const field self::TestPlatform fuchsia = #C6;
+  enum-element static const field self::TestPlatform ios = #C9;
+  enum-element static const field self::TestPlatform linux = #C12;
+  enum-element static const field self::TestPlatform macos = #C15;
+  enum-element static const field self::TestPlatform windows = #C18;
+  const synthetic constructor •(core::int #index, core::String #name) → self::TestPlatform
+    : super core::_Enum::•(#index, #name)
+    ;
+  method _enumToString() → core::String
+    return "TestPlatform.${this.{core::_Enum::_name}{core::String}}";
+}
+static const field core::bool kDebugMode = #C20;
+static field self::TestPlatform? debugDefaultTestPlatform;
+static const field core::bool enableAsserts = #C21;
+static method testAndroid(core::int i) → void {
+  final core::bool b = #C20;
+  core::print(b);
+}
+static method testFuchsia(core::int i) → void {
+  final core::bool b = #C20;
+  core::print(b);
+}
+static method testIOS(core::int i) → void {
+  final core::bool b = #C20;
+  core::print(b);
+}
+static method testLinux(core::int i) → void {
+  final core::bool b = #C21;
+  core::print(b);
+  {
+    final core::String os = #C11;
+    core::print(os);
+    final core::String sep = #C22;
+    core::print(sep);
+  }
+}
+static method testMacOS(core::int i) → void {
+  final core::bool b = #C20;
+  core::print(b);
+}
+static method testWindows(core::int i) → void {
+  final core::bool b = #C20;
+  core::print(b);
+}
+static method testSwitchStatements(core::int i) → void {
+  #L1:
+  {
+    core::print("is linux");
+    break #L1;
+  }
+}
+@#C25
+static get defaultTestPlatform() → self::TestPlatform {
+  return #C12;
+  throw "Unexpected platform: ${#C11}";
+}
+static method testPragma(core::int i) → void {
+  core::print(#C12);
+  #L2:
+  {
+    core::print("is linux");
+    break #L2;
+  }
+}
+@#C27
+static get defaultTestPlatformOverridableWhenDebug() → self::TestPlatform {
+  late self::TestPlatform result;
+  {
+    result = #C12;
+  }
+  return result;
+}
+static method testConditionalPragma(core::int i) → void {
+  core::print(#C12);
+  #L3:
+  {
+    core::print("is linux");
+    break #L3;
+  }
+}
+@#C28
+static get defaultTestPlatformOverridableWithAsserts() → self::TestPlatform {
+  late self::TestPlatform result;
+  {
+    result = #C12;
+  }
+  assert((() → core::bool {
+    if(io::Platform::environment.{core::Map::containsKey}("FLUTTER_TEST"){(core::Object?) → core::bool}) {
+      result = #C3;
+    }
+    return true;
+  })(){() → core::bool});
+  return result;
+}
+static method testConditionalPragmaWithAsserts(core::int i) → void {
+  core::print(self::defaultTestPlatformOverridableWithAsserts);
+  #L4:
+  switch(self::defaultTestPlatformOverridableWithAsserts) /* isExplicitlyExhaustive, self::TestPlatform */ {
+    #L5:
+    case #C3:
+      {
+        core::print("is android");
+        break #L4;
+      }
+    #L6:
+    case #C6:
+      {
+        core::print("is fuchsia");
+        break #L4;
+      }
+    #L7:
+    case #C9:
+      {
+        core::print("is ios");
+        break #L4;
+      }
+    #L8:
+    case #C12:
+      {
+        core::print("is linux");
+        break #L4;
+      }
+    #L9:
+    case #C15:
+      {
+        core::print("is macos");
+        break #L4;
+      }
+    #L10:
+    case #C18:
+      {
+        core::print("is windows");
+        break #L4;
+      }
+  }
+}
+static method main(core::List<core::String> args) → dynamic {
+  if(args.{core::Iterable::isEmpty}{core::bool})
+    return;
+  final core::int i = core::int::parse(args.{core::List::[]}(0){(core::int) → core::String});
+  self::testAndroid(i);
+  self::testFuchsia(i);
+  self::testIOS(i);
+  self::testLinux(i);
+  self::testMacOS(i);
+  self::testWindows(i);
+  self::testSwitchStatements(i);
+  self::testPragma(i);
+  self::debugDefaultTestPlatform = #C3;
+  self::testConditionalPragma(i);
+  self::testConditionalPragmaWithAsserts(i);
+}
+constants  {
+  #C1 = 0
+  #C2 = "android"
+  #C3 = self::TestPlatform {index:#C1, _name:#C2}
+  #C4 = 1
+  #C5 = "fuchsia"
+  #C6 = self::TestPlatform {index:#C4, _name:#C5}
+  #C7 = 2
+  #C8 = "ios"
+  #C9 = self::TestPlatform {index:#C7, _name:#C8}
+  #C10 = 3
+  #C11 = "linux"
+  #C12 = self::TestPlatform {index:#C10, _name:#C11}
+  #C13 = 4
+  #C14 = "macos"
+  #C15 = self::TestPlatform {index:#C13, _name:#C14}
+  #C16 = 5
+  #C17 = "windows"
+  #C18 = self::TestPlatform {index:#C16, _name:#C17}
+  #C19 = <self::TestPlatform>[#C3, #C6, #C9, #C12, #C15, #C18]
+  #C20 = false
+  #C21 = true
+  #C22 = "/"
+  #C23 = "vm:platform-const"
+  #C24 = null
+  #C25 = core::pragma {name:#C23, options:#C24}
+  #C26 = "vm:platform-const-if"
+  #C27 = core::pragma {name:#C26, options:#C21}
+  #C28 = core::pragma {name:#C26, options:#C20}
+}
diff --git a/pkg/vm/testcases/transformations/vm_constant_evaluator/platform_testcases.dart.macos.debug.expect b/pkg/vm/testcases/transformations/vm_constant_evaluator/platform_testcases.dart.macos.debug.expect
new file mode 100644
index 0000000..cad2da9
--- /dev/null
+++ b/pkg/vm/testcases/transformations/vm_constant_evaluator/platform_testcases.dart.macos.debug.expect
@@ -0,0 +1,188 @@
+library #lib;
+import self as self;
+import "dart:core" as core;
+
+import "dart:io";
+
+class TestPlatform extends core::_Enum /*isEnum*/  {
+  static const field core::List<self::TestPlatform> values = #C19;
+  enum-element static const field self::TestPlatform android = #C3;
+  enum-element static const field self::TestPlatform fuchsia = #C6;
+  enum-element static const field self::TestPlatform ios = #C9;
+  enum-element static const field self::TestPlatform linux = #C12;
+  enum-element static const field self::TestPlatform macos = #C15;
+  enum-element static const field self::TestPlatform windows = #C18;
+  const synthetic constructor •(core::int #index, core::String #name) → self::TestPlatform
+    : super core::_Enum::•(#index, #name)
+    ;
+  method _enumToString() → core::String
+    return "TestPlatform.${this.{core::_Enum::_name}{core::String}}";
+}
+static const field core::bool kDebugMode = #C20;
+static field self::TestPlatform? debugDefaultTestPlatform;
+static const field core::bool enableAsserts = #C21;
+static method testAndroid(core::int i) → void {
+  final core::bool b = #C21;
+  core::print(b);
+}
+static method testFuchsia(core::int i) → void {
+  final core::bool b = #C21;
+  core::print(b);
+}
+static method testIOS(core::int i) → void {
+  final core::bool b = #C21;
+  core::print(b);
+}
+static method testLinux(core::int i) → void {
+  final core::bool b = #C21;
+  core::print(b);
+}
+static method testMacOS(core::int i) → void {
+  final core::bool b = #C20;
+  core::print(b);
+  {
+    final core::String os = #C14;
+    core::print(os);
+    final core::String sep = #C22;
+    core::print(sep);
+  }
+}
+static method testWindows(core::int i) → void {
+  final core::bool b = #C21;
+  core::print(b);
+}
+static method testSwitchStatements(core::int i) → void {
+  #L1:
+  {
+    core::print("is macos");
+    break #L1;
+  }
+}
+@#C25
+static get defaultTestPlatform() → self::TestPlatform {
+  return #C15;
+  throw "Unexpected platform: ${#C14}";
+}
+static method testPragma(core::int i) → void {
+  core::print(#C15);
+  #L2:
+  {
+    core::print("is macos");
+    break #L2;
+  }
+}
+@#C27
+static get defaultTestPlatformOverridableWhenDebug() → self::TestPlatform {
+  late self::TestPlatform result;
+  {
+    result = #C15;
+  }
+  if(!(self::debugDefaultTestPlatform == null)) {
+    result = self::debugDefaultTestPlatform!;
+  }
+  return result;
+}
+static method testConditionalPragma(core::int i) → void {
+  core::print(self::defaultTestPlatformOverridableWhenDebug);
+  #L3:
+  switch(self::defaultTestPlatformOverridableWhenDebug) /* isExplicitlyExhaustive, self::TestPlatform */ {
+    #L4:
+    case #C3:
+      {
+        core::print("is android");
+        break #L3;
+      }
+    #L5:
+    case #C6:
+      {
+        core::print("is fuchsia");
+        break #L3;
+      }
+    #L6:
+    case #C9:
+      {
+        core::print("is ios");
+        break #L3;
+      }
+    #L7:
+    case #C12:
+      {
+        core::print("is linux");
+        break #L3;
+      }
+    #L8:
+    case #C15:
+      {
+        core::print("is macos");
+        break #L3;
+      }
+    #L9:
+    case #C18:
+      {
+        core::print("is windows");
+        break #L3;
+      }
+  }
+}
+@#C28
+static get defaultTestPlatformOverridableWithAsserts() → self::TestPlatform {
+  late self::TestPlatform result;
+  {
+    result = #C15;
+  }
+  return result;
+}
+static method testConditionalPragmaWithAsserts(core::int i) → void {
+  core::print(#C15);
+  #L10:
+  {
+    core::print("is macos");
+    break #L10;
+  }
+}
+static method main(core::List<core::String> args) → dynamic {
+  if(args.{core::Iterable::isEmpty}{core::bool})
+    return;
+  final core::int i = core::int::parse(args.{core::List::[]}(0){(core::int) → core::String});
+  self::testAndroid(i);
+  self::testFuchsia(i);
+  self::testIOS(i);
+  self::testLinux(i);
+  self::testMacOS(i);
+  self::testWindows(i);
+  self::testSwitchStatements(i);
+  self::testPragma(i);
+  self::debugDefaultTestPlatform = #C3;
+  self::testConditionalPragma(i);
+  self::testConditionalPragmaWithAsserts(i);
+}
+constants  {
+  #C1 = 0
+  #C2 = "android"
+  #C3 = self::TestPlatform {index:#C1, _name:#C2}
+  #C4 = 1
+  #C5 = "fuchsia"
+  #C6 = self::TestPlatform {index:#C4, _name:#C5}
+  #C7 = 2
+  #C8 = "ios"
+  #C9 = self::TestPlatform {index:#C7, _name:#C8}
+  #C10 = 3
+  #C11 = "linux"
+  #C12 = self::TestPlatform {index:#C10, _name:#C11}
+  #C13 = 4
+  #C14 = "macos"
+  #C15 = self::TestPlatform {index:#C13, _name:#C14}
+  #C16 = 5
+  #C17 = "windows"
+  #C18 = self::TestPlatform {index:#C16, _name:#C17}
+  #C19 = <self::TestPlatform>[#C3, #C6, #C9, #C12, #C15, #C18]
+  #C20 = true
+  #C21 = false
+  #C22 = "/"
+  #C23 = "vm:platform-const"
+  #C24 = null
+  #C25 = core::pragma {name:#C23, options:#C24}
+  #C26 = "vm:platform-const-if"
+  #C27 = core::pragma {name:#C26, options:#C21}
+  #C28 = core::pragma {name:#C26, options:#C20}
+}
diff --git a/pkg/vm/testcases/transformations/vm_constant_evaluator/platform_testcases.dart.macos.debug.withAsserts.expect b/pkg/vm/testcases/transformations/vm_constant_evaluator/platform_testcases.dart.macos.debug.withAsserts.expect
new file mode 100644
index 0000000..53ea073
--- /dev/null
+++ b/pkg/vm/testcases/transformations/vm_constant_evaluator/platform_testcases.dart.macos.debug.withAsserts.expect
@@ -0,0 +1,228 @@
+library #lib;
+import self as self;
+import "dart:core" as core;
+import "dart:io" as io;
+
+import "dart:io";
+
+class TestPlatform extends core::_Enum /*isEnum*/  {
+  static const field core::List<self::TestPlatform> values = #C19;
+  enum-element static const field self::TestPlatform android = #C3;
+  enum-element static const field self::TestPlatform fuchsia = #C6;
+  enum-element static const field self::TestPlatform ios = #C9;
+  enum-element static const field self::TestPlatform linux = #C12;
+  enum-element static const field self::TestPlatform macos = #C15;
+  enum-element static const field self::TestPlatform windows = #C18;
+  const synthetic constructor •(core::int #index, core::String #name) → self::TestPlatform
+    : super core::_Enum::•(#index, #name)
+    ;
+  method _enumToString() → core::String
+    return "TestPlatform.${this.{core::_Enum::_name}{core::String}}";
+}
+static const field core::bool kDebugMode = #C20;
+static field self::TestPlatform? debugDefaultTestPlatform;
+static const field core::bool enableAsserts = #C20;
+static method testAndroid(core::int i) → void {
+  final core::bool b = #C21;
+  core::print(b);
+}
+static method testFuchsia(core::int i) → void {
+  final core::bool b = #C21;
+  core::print(b);
+}
+static method testIOS(core::int i) → void {
+  final core::bool b = #C21;
+  core::print(b);
+}
+static method testLinux(core::int i) → void {
+  final core::bool b = #C21;
+  core::print(b);
+}
+static method testMacOS(core::int i) → void {
+  final core::bool b = #C20;
+  core::print(b);
+  {
+    final core::String os = #C14;
+    core::print(os);
+    final core::String sep = #C22;
+    core::print(sep);
+  }
+}
+static method testWindows(core::int i) → void {
+  final core::bool b = #C21;
+  core::print(b);
+}
+static method testSwitchStatements(core::int i) → void {
+  #L1:
+  {
+    core::print("is macos");
+    break #L1;
+  }
+}
+@#C25
+static get defaultTestPlatform() → self::TestPlatform {
+  return #C15;
+  throw "Unexpected platform: ${#C14}";
+}
+static method testPragma(core::int i) → void {
+  core::print(#C15);
+  #L2:
+  {
+    core::print("is macos");
+    break #L2;
+  }
+}
+@#C27
+static get defaultTestPlatformOverridableWhenDebug() → self::TestPlatform {
+  late self::TestPlatform result;
+  {
+    result = #C15;
+  }
+  if(!(self::debugDefaultTestPlatform == null)) {
+    result = self::debugDefaultTestPlatform!;
+  }
+  return result;
+}
+static method testConditionalPragma(core::int i) → void {
+  core::print(self::defaultTestPlatformOverridableWhenDebug);
+  #L3:
+  switch(self::defaultTestPlatformOverridableWhenDebug) /* isExplicitlyExhaustive, self::TestPlatform */ {
+    #L4:
+    case #C3:
+      {
+        core::print("is android");
+        break #L3;
+      }
+    #L5:
+    case #C6:
+      {
+        core::print("is fuchsia");
+        break #L3;
+      }
+    #L6:
+    case #C9:
+      {
+        core::print("is ios");
+        break #L3;
+      }
+    #L7:
+    case #C12:
+      {
+        core::print("is linux");
+        break #L3;
+      }
+    #L8:
+    case #C15:
+      {
+        core::print("is macos");
+        break #L3;
+      }
+    #L9:
+    case #C18:
+      {
+        core::print("is windows");
+        break #L3;
+      }
+  }
+}
+@#C27
+static get defaultTestPlatformOverridableWithAsserts() → self::TestPlatform {
+  late self::TestPlatform result;
+  {
+    result = #C15;
+  }
+  assert((() → core::bool {
+    if(io::Platform::environment.{core::Map::containsKey}("FLUTTER_TEST"){(core::Object?) → core::bool}) {
+      result = #C3;
+    }
+    return true;
+  })(){() → core::bool});
+  return result;
+}
+static method testConditionalPragmaWithAsserts(core::int i) → void {
+  core::print(self::defaultTestPlatformOverridableWithAsserts);
+  #L10:
+  switch(self::defaultTestPlatformOverridableWithAsserts) /* isExplicitlyExhaustive, self::TestPlatform */ {
+    #L11:
+    case #C3:
+      {
+        core::print("is android");
+        break #L10;
+      }
+    #L12:
+    case #C6:
+      {
+        core::print("is fuchsia");
+        break #L10;
+      }
+    #L13:
+    case #C9:
+      {
+        core::print("is ios");
+        break #L10;
+      }
+    #L14:
+    case #C12:
+      {
+        core::print("is linux");
+        break #L10;
+      }
+    #L15:
+    case #C15:
+      {
+        core::print("is macos");
+        break #L10;
+      }
+    #L16:
+    case #C18:
+      {
+        core::print("is windows");
+        break #L10;
+      }
+  }
+}
+static method main(core::List<core::String> args) → dynamic {
+  if(args.{core::Iterable::isEmpty}{core::bool})
+    return;
+  final core::int i = core::int::parse(args.{core::List::[]}(0){(core::int) → core::String});
+  self::testAndroid(i);
+  self::testFuchsia(i);
+  self::testIOS(i);
+  self::testLinux(i);
+  self::testMacOS(i);
+  self::testWindows(i);
+  self::testSwitchStatements(i);
+  self::testPragma(i);
+  self::debugDefaultTestPlatform = #C3;
+  self::testConditionalPragma(i);
+  self::testConditionalPragmaWithAsserts(i);
+}
+constants  {
+  #C1 = 0
+  #C2 = "android"
+  #C3 = self::TestPlatform {index:#C1, _name:#C2}
+  #C4 = 1
+  #C5 = "fuchsia"
+  #C6 = self::TestPlatform {index:#C4, _name:#C5}
+  #C7 = 2
+  #C8 = "ios"
+  #C9 = self::TestPlatform {index:#C7, _name:#C8}
+  #C10 = 3
+  #C11 = "linux"
+  #C12 = self::TestPlatform {index:#C10, _name:#C11}
+  #C13 = 4
+  #C14 = "macos"
+  #C15 = self::TestPlatform {index:#C13, _name:#C14}
+  #C16 = 5
+  #C17 = "windows"
+  #C18 = self::TestPlatform {index:#C16, _name:#C17}
+  #C19 = <self::TestPlatform>[#C3, #C6, #C9, #C12, #C15, #C18]
+  #C20 = true
+  #C21 = false
+  #C22 = "/"
+  #C23 = "vm:platform-const"
+  #C24 = null
+  #C25 = core::pragma {name:#C23, options:#C24}
+  #C26 = "vm:platform-const-if"
+  #C27 = core::pragma {name:#C26, options:#C21}
+}
diff --git a/pkg/vm/testcases/transformations/vm_constant_evaluator/platform_testcases.dart.macos.expect b/pkg/vm/testcases/transformations/vm_constant_evaluator/platform_testcases.dart.macos.expect
index 26513c1..3929ac6 100644
--- a/pkg/vm/testcases/transformations/vm_constant_evaluator/platform_testcases.dart.macos.expect
+++ b/pkg/vm/testcases/transformations/vm_constant_evaluator/platform_testcases.dart.macos.expect
@@ -18,6 +18,9 @@
   method _enumToString() → core::String
     return "TestPlatform.${this.{core::_Enum::_name}{core::String}}";
 }
+static const field core::bool kDebugMode = #C20;
+static field self::TestPlatform? debugDefaultTestPlatform;
+static const field core::bool enableAsserts = #C20;
 static method testAndroid(core::int i) → void {
   final core::bool b = #C20;
   core::print(b);
@@ -58,7 +61,7 @@
 @#C25
 static get defaultTestPlatform() → self::TestPlatform {
   return #C15;
-  throw "Unexpected platform";
+  throw "Unexpected platform: ${#C14}";
 }
 static method testPragma(core::int i) → void {
   core::print(#C15);
@@ -68,6 +71,38 @@
     break #L2;
   }
 }
+@#C27
+static get defaultTestPlatformOverridableWhenDebug() → self::TestPlatform {
+  late self::TestPlatform result;
+  {
+    result = #C15;
+  }
+  return result;
+}
+static method testConditionalPragma(core::int i) → void {
+  core::print(#C15);
+  #L3:
+  {
+    core::print("is macos");
+    break #L3;
+  }
+}
+@#C27
+static get defaultTestPlatformOverridableWithAsserts() → self::TestPlatform {
+  late self::TestPlatform result;
+  {
+    result = #C15;
+  }
+  return result;
+}
+static method testConditionalPragmaWithAsserts(core::int i) → void {
+  core::print(#C15);
+  #L4:
+  {
+    core::print("is macos");
+    break #L4;
+  }
+}
 static method main(core::List<core::String> args) → dynamic {
   if(args.{core::Iterable::isEmpty}{core::bool})
     return;
@@ -80,6 +115,9 @@
   self::testWindows(i);
   self::testSwitchStatements(i);
   self::testPragma(i);
+  self::debugDefaultTestPlatform = #C3;
+  self::testConditionalPragma(i);
+  self::testConditionalPragmaWithAsserts(i);
 }
 constants  {
   #C1 = 0
@@ -107,4 +145,6 @@
   #C23 = "vm:platform-const"
   #C24 = null
   #C25 = core::pragma {name:#C23, options:#C24}
+  #C26 = "vm:platform-const-if"
+  #C27 = core::pragma {name:#C26, options:#C21}
 }
diff --git a/pkg/vm/testcases/transformations/vm_constant_evaluator/platform_testcases.dart.macos.withAsserts.expect b/pkg/vm/testcases/transformations/vm_constant_evaluator/platform_testcases.dart.macos.withAsserts.expect
new file mode 100644
index 0000000..2a30497
--- /dev/null
+++ b/pkg/vm/testcases/transformations/vm_constant_evaluator/platform_testcases.dart.macos.withAsserts.expect
@@ -0,0 +1,192 @@
+library #lib;
+import self as self;
+import "dart:core" as core;
+import "dart:io" as io;
+
+import "dart:io";
+
+class TestPlatform extends core::_Enum /*isEnum*/  {
+  static const field core::List<self::TestPlatform> values = #C19;
+  enum-element static const field self::TestPlatform android = #C3;
+  enum-element static const field self::TestPlatform fuchsia = #C6;
+  enum-element static const field self::TestPlatform ios = #C9;
+  enum-element static const field self::TestPlatform linux = #C12;
+  enum-element static const field self::TestPlatform macos = #C15;
+  enum-element static const field self::TestPlatform windows = #C18;
+  const synthetic constructor •(core::int #index, core::String #name) → self::TestPlatform
+    : super core::_Enum::•(#index, #name)
+    ;
+  method _enumToString() → core::String
+    return "TestPlatform.${this.{core::_Enum::_name}{core::String}}";
+}
+static const field core::bool kDebugMode = #C20;
+static field self::TestPlatform? debugDefaultTestPlatform;
+static const field core::bool enableAsserts = #C21;
+static method testAndroid(core::int i) → void {
+  final core::bool b = #C20;
+  core::print(b);
+}
+static method testFuchsia(core::int i) → void {
+  final core::bool b = #C20;
+  core::print(b);
+}
+static method testIOS(core::int i) → void {
+  final core::bool b = #C20;
+  core::print(b);
+}
+static method testLinux(core::int i) → void {
+  final core::bool b = #C20;
+  core::print(b);
+}
+static method testMacOS(core::int i) → void {
+  final core::bool b = #C21;
+  core::print(b);
+  {
+    final core::String os = #C14;
+    core::print(os);
+    final core::String sep = #C22;
+    core::print(sep);
+  }
+}
+static method testWindows(core::int i) → void {
+  final core::bool b = #C20;
+  core::print(b);
+}
+static method testSwitchStatements(core::int i) → void {
+  #L1:
+  {
+    core::print("is macos");
+    break #L1;
+  }
+}
+@#C25
+static get defaultTestPlatform() → self::TestPlatform {
+  return #C15;
+  throw "Unexpected platform: ${#C14}";
+}
+static method testPragma(core::int i) → void {
+  core::print(#C15);
+  #L2:
+  {
+    core::print("is macos");
+    break #L2;
+  }
+}
+@#C27
+static get defaultTestPlatformOverridableWhenDebug() → self::TestPlatform {
+  late self::TestPlatform result;
+  {
+    result = #C15;
+  }
+  return result;
+}
+static method testConditionalPragma(core::int i) → void {
+  core::print(#C15);
+  #L3:
+  {
+    core::print("is macos");
+    break #L3;
+  }
+}
+@#C28
+static get defaultTestPlatformOverridableWithAsserts() → self::TestPlatform {
+  late self::TestPlatform result;
+  {
+    result = #C15;
+  }
+  assert((() → core::bool {
+    if(io::Platform::environment.{core::Map::containsKey}("FLUTTER_TEST"){(core::Object?) → core::bool}) {
+      result = #C3;
+    }
+    return true;
+  })(){() → core::bool});
+  return result;
+}
+static method testConditionalPragmaWithAsserts(core::int i) → void {
+  core::print(self::defaultTestPlatformOverridableWithAsserts);
+  #L4:
+  switch(self::defaultTestPlatformOverridableWithAsserts) /* isExplicitlyExhaustive, self::TestPlatform */ {
+    #L5:
+    case #C3:
+      {
+        core::print("is android");
+        break #L4;
+      }
+    #L6:
+    case #C6:
+      {
+        core::print("is fuchsia");
+        break #L4;
+      }
+    #L7:
+    case #C9:
+      {
+        core::print("is ios");
+        break #L4;
+      }
+    #L8:
+    case #C12:
+      {
+        core::print("is linux");
+        break #L4;
+      }
+    #L9:
+    case #C15:
+      {
+        core::print("is macos");
+        break #L4;
+      }
+    #L10:
+    case #C18:
+      {
+        core::print("is windows");
+        break #L4;
+      }
+  }
+}
+static method main(core::List<core::String> args) → dynamic {
+  if(args.{core::Iterable::isEmpty}{core::bool})
+    return;
+  final core::int i = core::int::parse(args.{core::List::[]}(0){(core::int) → core::String});
+  self::testAndroid(i);
+  self::testFuchsia(i);
+  self::testIOS(i);
+  self::testLinux(i);
+  self::testMacOS(i);
+  self::testWindows(i);
+  self::testSwitchStatements(i);
+  self::testPragma(i);
+  self::debugDefaultTestPlatform = #C3;
+  self::testConditionalPragma(i);
+  self::testConditionalPragmaWithAsserts(i);
+}
+constants  {
+  #C1 = 0
+  #C2 = "android"
+  #C3 = self::TestPlatform {index:#C1, _name:#C2}
+  #C4 = 1
+  #C5 = "fuchsia"
+  #C6 = self::TestPlatform {index:#C4, _name:#C5}
+  #C7 = 2
+  #C8 = "ios"
+  #C9 = self::TestPlatform {index:#C7, _name:#C8}
+  #C10 = 3
+  #C11 = "linux"
+  #C12 = self::TestPlatform {index:#C10, _name:#C11}
+  #C13 = 4
+  #C14 = "macos"
+  #C15 = self::TestPlatform {index:#C13, _name:#C14}
+  #C16 = 5
+  #C17 = "windows"
+  #C18 = self::TestPlatform {index:#C16, _name:#C17}
+  #C19 = <self::TestPlatform>[#C3, #C6, #C9, #C12, #C15, #C18]
+  #C20 = false
+  #C21 = true
+  #C22 = "/"
+  #C23 = "vm:platform-const"
+  #C24 = null
+  #C25 = core::pragma {name:#C23, options:#C24}
+  #C26 = "vm:platform-const-if"
+  #C27 = core::pragma {name:#C26, options:#C21}
+  #C28 = core::pragma {name:#C26, options:#C20}
+}
diff --git a/pkg/vm/testcases/transformations/vm_constant_evaluator/platform_testcases.dart.windows.debug.expect b/pkg/vm/testcases/transformations/vm_constant_evaluator/platform_testcases.dart.windows.debug.expect
new file mode 100644
index 0000000..75eff0c
--- /dev/null
+++ b/pkg/vm/testcases/transformations/vm_constant_evaluator/platform_testcases.dart.windows.debug.expect
@@ -0,0 +1,188 @@
+library #lib;
+import self as self;
+import "dart:core" as core;
+
+import "dart:io";
+
+class TestPlatform extends core::_Enum /*isEnum*/  {
+  static const field core::List<self::TestPlatform> values = #C19;
+  enum-element static const field self::TestPlatform android = #C3;
+  enum-element static const field self::TestPlatform fuchsia = #C6;
+  enum-element static const field self::TestPlatform ios = #C9;
+  enum-element static const field self::TestPlatform linux = #C12;
+  enum-element static const field self::TestPlatform macos = #C15;
+  enum-element static const field self::TestPlatform windows = #C18;
+  const synthetic constructor •(core::int #index, core::String #name) → self::TestPlatform
+    : super core::_Enum::•(#index, #name)
+    ;
+  method _enumToString() → core::String
+    return "TestPlatform.${this.{core::_Enum::_name}{core::String}}";
+}
+static const field core::bool kDebugMode = #C20;
+static field self::TestPlatform? debugDefaultTestPlatform;
+static const field core::bool enableAsserts = #C21;
+static method testAndroid(core::int i) → void {
+  final core::bool b = #C21;
+  core::print(b);
+}
+static method testFuchsia(core::int i) → void {
+  final core::bool b = #C21;
+  core::print(b);
+}
+static method testIOS(core::int i) → void {
+  final core::bool b = #C21;
+  core::print(b);
+}
+static method testLinux(core::int i) → void {
+  final core::bool b = #C21;
+  core::print(b);
+}
+static method testMacOS(core::int i) → void {
+  final core::bool b = #C21;
+  core::print(b);
+}
+static method testWindows(core::int i) → void {
+  final core::bool b = #C20;
+  core::print(b);
+  {
+    final core::String os = #C17;
+    core::print(os);
+    final core::String sep = #C22;
+    core::print(sep);
+  }
+}
+static method testSwitchStatements(core::int i) → void {
+  #L1:
+  {
+    core::print("is windows");
+    break #L1;
+  }
+}
+@#C25
+static get defaultTestPlatform() → self::TestPlatform {
+  return #C18;
+  throw "Unexpected platform: ${#C17}";
+}
+static method testPragma(core::int i) → void {
+  core::print(#C18);
+  #L2:
+  {
+    core::print("is windows");
+    break #L2;
+  }
+}
+@#C27
+static get defaultTestPlatformOverridableWhenDebug() → self::TestPlatform {
+  late self::TestPlatform result;
+  {
+    result = #C18;
+  }
+  if(!(self::debugDefaultTestPlatform == null)) {
+    result = self::debugDefaultTestPlatform!;
+  }
+  return result;
+}
+static method testConditionalPragma(core::int i) → void {
+  core::print(self::defaultTestPlatformOverridableWhenDebug);
+  #L3:
+  switch(self::defaultTestPlatformOverridableWhenDebug) /* isExplicitlyExhaustive, self::TestPlatform */ {
+    #L4:
+    case #C3:
+      {
+        core::print("is android");
+        break #L3;
+      }
+    #L5:
+    case #C6:
+      {
+        core::print("is fuchsia");
+        break #L3;
+      }
+    #L6:
+    case #C9:
+      {
+        core::print("is ios");
+        break #L3;
+      }
+    #L7:
+    case #C12:
+      {
+        core::print("is linux");
+        break #L3;
+      }
+    #L8:
+    case #C15:
+      {
+        core::print("is macos");
+        break #L3;
+      }
+    #L9:
+    case #C18:
+      {
+        core::print("is windows");
+        break #L3;
+      }
+  }
+}
+@#C28
+static get defaultTestPlatformOverridableWithAsserts() → self::TestPlatform {
+  late self::TestPlatform result;
+  {
+    result = #C18;
+  }
+  return result;
+}
+static method testConditionalPragmaWithAsserts(core::int i) → void {
+  core::print(#C18);
+  #L10:
+  {
+    core::print("is windows");
+    break #L10;
+  }
+}
+static method main(core::List<core::String> args) → dynamic {
+  if(args.{core::Iterable::isEmpty}{core::bool})
+    return;
+  final core::int i = core::int::parse(args.{core::List::[]}(0){(core::int) → core::String});
+  self::testAndroid(i);
+  self::testFuchsia(i);
+  self::testIOS(i);
+  self::testLinux(i);
+  self::testMacOS(i);
+  self::testWindows(i);
+  self::testSwitchStatements(i);
+  self::testPragma(i);
+  self::debugDefaultTestPlatform = #C3;
+  self::testConditionalPragma(i);
+  self::testConditionalPragmaWithAsserts(i);
+}
+constants  {
+  #C1 = 0
+  #C2 = "android"
+  #C3 = self::TestPlatform {index:#C1, _name:#C2}
+  #C4 = 1
+  #C5 = "fuchsia"
+  #C6 = self::TestPlatform {index:#C4, _name:#C5}
+  #C7 = 2
+  #C8 = "ios"
+  #C9 = self::TestPlatform {index:#C7, _name:#C8}
+  #C10 = 3
+  #C11 = "linux"
+  #C12 = self::TestPlatform {index:#C10, _name:#C11}
+  #C13 = 4
+  #C14 = "macos"
+  #C15 = self::TestPlatform {index:#C13, _name:#C14}
+  #C16 = 5
+  #C17 = "windows"
+  #C18 = self::TestPlatform {index:#C16, _name:#C17}
+  #C19 = <self::TestPlatform>[#C3, #C6, #C9, #C12, #C15, #C18]
+  #C20 = true
+  #C21 = false
+  #C22 = "\\"
+  #C23 = "vm:platform-const"
+  #C24 = null
+  #C25 = core::pragma {name:#C23, options:#C24}
+  #C26 = "vm:platform-const-if"
+  #C27 = core::pragma {name:#C26, options:#C21}
+  #C28 = core::pragma {name:#C26, options:#C20}
+}
diff --git a/pkg/vm/testcases/transformations/vm_constant_evaluator/platform_testcases.dart.windows.debug.withAsserts.expect b/pkg/vm/testcases/transformations/vm_constant_evaluator/platform_testcases.dart.windows.debug.withAsserts.expect
new file mode 100644
index 0000000..8cb053c
--- /dev/null
+++ b/pkg/vm/testcases/transformations/vm_constant_evaluator/platform_testcases.dart.windows.debug.withAsserts.expect
@@ -0,0 +1,228 @@
+library #lib;
+import self as self;
+import "dart:core" as core;
+import "dart:io" as io;
+
+import "dart:io";
+
+class TestPlatform extends core::_Enum /*isEnum*/  {
+  static const field core::List<self::TestPlatform> values = #C19;
+  enum-element static const field self::TestPlatform android = #C3;
+  enum-element static const field self::TestPlatform fuchsia = #C6;
+  enum-element static const field self::TestPlatform ios = #C9;
+  enum-element static const field self::TestPlatform linux = #C12;
+  enum-element static const field self::TestPlatform macos = #C15;
+  enum-element static const field self::TestPlatform windows = #C18;
+  const synthetic constructor •(core::int #index, core::String #name) → self::TestPlatform
+    : super core::_Enum::•(#index, #name)
+    ;
+  method _enumToString() → core::String
+    return "TestPlatform.${this.{core::_Enum::_name}{core::String}}";
+}
+static const field core::bool kDebugMode = #C20;
+static field self::TestPlatform? debugDefaultTestPlatform;
+static const field core::bool enableAsserts = #C20;
+static method testAndroid(core::int i) → void {
+  final core::bool b = #C21;
+  core::print(b);
+}
+static method testFuchsia(core::int i) → void {
+  final core::bool b = #C21;
+  core::print(b);
+}
+static method testIOS(core::int i) → void {
+  final core::bool b = #C21;
+  core::print(b);
+}
+static method testLinux(core::int i) → void {
+  final core::bool b = #C21;
+  core::print(b);
+}
+static method testMacOS(core::int i) → void {
+  final core::bool b = #C21;
+  core::print(b);
+}
+static method testWindows(core::int i) → void {
+  final core::bool b = #C20;
+  core::print(b);
+  {
+    final core::String os = #C17;
+    core::print(os);
+    final core::String sep = #C22;
+    core::print(sep);
+  }
+}
+static method testSwitchStatements(core::int i) → void {
+  #L1:
+  {
+    core::print("is windows");
+    break #L1;
+  }
+}
+@#C25
+static get defaultTestPlatform() → self::TestPlatform {
+  return #C18;
+  throw "Unexpected platform: ${#C17}";
+}
+static method testPragma(core::int i) → void {
+  core::print(#C18);
+  #L2:
+  {
+    core::print("is windows");
+    break #L2;
+  }
+}
+@#C27
+static get defaultTestPlatformOverridableWhenDebug() → self::TestPlatform {
+  late self::TestPlatform result;
+  {
+    result = #C18;
+  }
+  if(!(self::debugDefaultTestPlatform == null)) {
+    result = self::debugDefaultTestPlatform!;
+  }
+  return result;
+}
+static method testConditionalPragma(core::int i) → void {
+  core::print(self::defaultTestPlatformOverridableWhenDebug);
+  #L3:
+  switch(self::defaultTestPlatformOverridableWhenDebug) /* isExplicitlyExhaustive, self::TestPlatform */ {
+    #L4:
+    case #C3:
+      {
+        core::print("is android");
+        break #L3;
+      }
+    #L5:
+    case #C6:
+      {
+        core::print("is fuchsia");
+        break #L3;
+      }
+    #L6:
+    case #C9:
+      {
+        core::print("is ios");
+        break #L3;
+      }
+    #L7:
+    case #C12:
+      {
+        core::print("is linux");
+        break #L3;
+      }
+    #L8:
+    case #C15:
+      {
+        core::print("is macos");
+        break #L3;
+      }
+    #L9:
+    case #C18:
+      {
+        core::print("is windows");
+        break #L3;
+      }
+  }
+}
+@#C27
+static get defaultTestPlatformOverridableWithAsserts() → self::TestPlatform {
+  late self::TestPlatform result;
+  {
+    result = #C18;
+  }
+  assert((() → core::bool {
+    if(io::Platform::environment.{core::Map::containsKey}("FLUTTER_TEST"){(core::Object?) → core::bool}) {
+      result = #C3;
+    }
+    return true;
+  })(){() → core::bool});
+  return result;
+}
+static method testConditionalPragmaWithAsserts(core::int i) → void {
+  core::print(self::defaultTestPlatformOverridableWithAsserts);
+  #L10:
+  switch(self::defaultTestPlatformOverridableWithAsserts) /* isExplicitlyExhaustive, self::TestPlatform */ {
+    #L11:
+    case #C3:
+      {
+        core::print("is android");
+        break #L10;
+      }
+    #L12:
+    case #C6:
+      {
+        core::print("is fuchsia");
+        break #L10;
+      }
+    #L13:
+    case #C9:
+      {
+        core::print("is ios");
+        break #L10;
+      }
+    #L14:
+    case #C12:
+      {
+        core::print("is linux");
+        break #L10;
+      }
+    #L15:
+    case #C15:
+      {
+        core::print("is macos");
+        break #L10;
+      }
+    #L16:
+    case #C18:
+      {
+        core::print("is windows");
+        break #L10;
+      }
+  }
+}
+static method main(core::List<core::String> args) → dynamic {
+  if(args.{core::Iterable::isEmpty}{core::bool})
+    return;
+  final core::int i = core::int::parse(args.{core::List::[]}(0){(core::int) → core::String});
+  self::testAndroid(i);
+  self::testFuchsia(i);
+  self::testIOS(i);
+  self::testLinux(i);
+  self::testMacOS(i);
+  self::testWindows(i);
+  self::testSwitchStatements(i);
+  self::testPragma(i);
+  self::debugDefaultTestPlatform = #C3;
+  self::testConditionalPragma(i);
+  self::testConditionalPragmaWithAsserts(i);
+}
+constants  {
+  #C1 = 0
+  #C2 = "android"
+  #C3 = self::TestPlatform {index:#C1, _name:#C2}
+  #C4 = 1
+  #C5 = "fuchsia"
+  #C6 = self::TestPlatform {index:#C4, _name:#C5}
+  #C7 = 2
+  #C8 = "ios"
+  #C9 = self::TestPlatform {index:#C7, _name:#C8}
+  #C10 = 3
+  #C11 = "linux"
+  #C12 = self::TestPlatform {index:#C10, _name:#C11}
+  #C13 = 4
+  #C14 = "macos"
+  #C15 = self::TestPlatform {index:#C13, _name:#C14}
+  #C16 = 5
+  #C17 = "windows"
+  #C18 = self::TestPlatform {index:#C16, _name:#C17}
+  #C19 = <self::TestPlatform>[#C3, #C6, #C9, #C12, #C15, #C18]
+  #C20 = true
+  #C21 = false
+  #C22 = "\\"
+  #C23 = "vm:platform-const"
+  #C24 = null
+  #C25 = core::pragma {name:#C23, options:#C24}
+  #C26 = "vm:platform-const-if"
+  #C27 = core::pragma {name:#C26, options:#C21}
+}
diff --git a/pkg/vm/testcases/transformations/vm_constant_evaluator/platform_testcases.dart.windows.expect b/pkg/vm/testcases/transformations/vm_constant_evaluator/platform_testcases.dart.windows.expect
index f1086024..4271183 100644
--- a/pkg/vm/testcases/transformations/vm_constant_evaluator/platform_testcases.dart.windows.expect
+++ b/pkg/vm/testcases/transformations/vm_constant_evaluator/platform_testcases.dart.windows.expect
@@ -18,6 +18,9 @@
   method _enumToString() → core::String
     return "TestPlatform.${this.{core::_Enum::_name}{core::String}}";
 }
+static const field core::bool kDebugMode = #C20;
+static field self::TestPlatform? debugDefaultTestPlatform;
+static const field core::bool enableAsserts = #C20;
 static method testAndroid(core::int i) → void {
   final core::bool b = #C20;
   core::print(b);
@@ -58,7 +61,7 @@
 @#C25
 static get defaultTestPlatform() → self::TestPlatform {
   return #C18;
-  throw "Unexpected platform";
+  throw "Unexpected platform: ${#C17}";
 }
 static method testPragma(core::int i) → void {
   core::print(#C18);
@@ -68,6 +71,38 @@
     break #L2;
   }
 }
+@#C27
+static get defaultTestPlatformOverridableWhenDebug() → self::TestPlatform {
+  late self::TestPlatform result;
+  {
+    result = #C18;
+  }
+  return result;
+}
+static method testConditionalPragma(core::int i) → void {
+  core::print(#C18);
+  #L3:
+  {
+    core::print("is windows");
+    break #L3;
+  }
+}
+@#C27
+static get defaultTestPlatformOverridableWithAsserts() → self::TestPlatform {
+  late self::TestPlatform result;
+  {
+    result = #C18;
+  }
+  return result;
+}
+static method testConditionalPragmaWithAsserts(core::int i) → void {
+  core::print(#C18);
+  #L4:
+  {
+    core::print("is windows");
+    break #L4;
+  }
+}
 static method main(core::List<core::String> args) → dynamic {
   if(args.{core::Iterable::isEmpty}{core::bool})
     return;
@@ -80,6 +115,9 @@
   self::testWindows(i);
   self::testSwitchStatements(i);
   self::testPragma(i);
+  self::debugDefaultTestPlatform = #C3;
+  self::testConditionalPragma(i);
+  self::testConditionalPragmaWithAsserts(i);
 }
 constants  {
   #C1 = 0
@@ -107,4 +145,6 @@
   #C23 = "vm:platform-const"
   #C24 = null
   #C25 = core::pragma {name:#C23, options:#C24}
+  #C26 = "vm:platform-const-if"
+  #C27 = core::pragma {name:#C26, options:#C21}
 }
diff --git a/pkg/vm/testcases/transformations/vm_constant_evaluator/platform_testcases.dart.windows.withAsserts.expect b/pkg/vm/testcases/transformations/vm_constant_evaluator/platform_testcases.dart.windows.withAsserts.expect
new file mode 100644
index 0000000..a16c528
--- /dev/null
+++ b/pkg/vm/testcases/transformations/vm_constant_evaluator/platform_testcases.dart.windows.withAsserts.expect
@@ -0,0 +1,192 @@
+library #lib;
+import self as self;
+import "dart:core" as core;
+import "dart:io" as io;
+
+import "dart:io";
+
+class TestPlatform extends core::_Enum /*isEnum*/  {
+  static const field core::List<self::TestPlatform> values = #C19;
+  enum-element static const field self::TestPlatform android = #C3;
+  enum-element static const field self::TestPlatform fuchsia = #C6;
+  enum-element static const field self::TestPlatform ios = #C9;
+  enum-element static const field self::TestPlatform linux = #C12;
+  enum-element static const field self::TestPlatform macos = #C15;
+  enum-element static const field self::TestPlatform windows = #C18;
+  const synthetic constructor •(core::int #index, core::String #name) → self::TestPlatform
+    : super core::_Enum::•(#index, #name)
+    ;
+  method _enumToString() → core::String
+    return "TestPlatform.${this.{core::_Enum::_name}{core::String}}";
+}
+static const field core::bool kDebugMode = #C20;
+static field self::TestPlatform? debugDefaultTestPlatform;
+static const field core::bool enableAsserts = #C21;
+static method testAndroid(core::int i) → void {
+  final core::bool b = #C20;
+  core::print(b);
+}
+static method testFuchsia(core::int i) → void {
+  final core::bool b = #C20;
+  core::print(b);
+}
+static method testIOS(core::int i) → void {
+  final core::bool b = #C20;
+  core::print(b);
+}
+static method testLinux(core::int i) → void {
+  final core::bool b = #C20;
+  core::print(b);
+}
+static method testMacOS(core::int i) → void {
+  final core::bool b = #C20;
+  core::print(b);
+}
+static method testWindows(core::int i) → void {
+  final core::bool b = #C21;
+  core::print(b);
+  {
+    final core::String os = #C17;
+    core::print(os);
+    final core::String sep = #C22;
+    core::print(sep);
+  }
+}
+static method testSwitchStatements(core::int i) → void {
+  #L1:
+  {
+    core::print("is windows");
+    break #L1;
+  }
+}
+@#C25
+static get defaultTestPlatform() → self::TestPlatform {
+  return #C18;
+  throw "Unexpected platform: ${#C17}";
+}
+static method testPragma(core::int i) → void {
+  core::print(#C18);
+  #L2:
+  {
+    core::print("is windows");
+    break #L2;
+  }
+}
+@#C27
+static get defaultTestPlatformOverridableWhenDebug() → self::TestPlatform {
+  late self::TestPlatform result;
+  {
+    result = #C18;
+  }
+  return result;
+}
+static method testConditionalPragma(core::int i) → void {
+  core::print(#C18);
+  #L3:
+  {
+    core::print("is windows");
+    break #L3;
+  }
+}
+@#C28
+static get defaultTestPlatformOverridableWithAsserts() → self::TestPlatform {
+  late self::TestPlatform result;
+  {
+    result = #C18;
+  }
+  assert((() → core::bool {
+    if(io::Platform::environment.{core::Map::containsKey}("FLUTTER_TEST"){(core::Object?) → core::bool}) {
+      result = #C3;
+    }
+    return true;
+  })(){() → core::bool});
+  return result;
+}
+static method testConditionalPragmaWithAsserts(core::int i) → void {
+  core::print(self::defaultTestPlatformOverridableWithAsserts);
+  #L4:
+  switch(self::defaultTestPlatformOverridableWithAsserts) /* isExplicitlyExhaustive, self::TestPlatform */ {
+    #L5:
+    case #C3:
+      {
+        core::print("is android");
+        break #L4;
+      }
+    #L6:
+    case #C6:
+      {
+        core::print("is fuchsia");
+        break #L4;
+      }
+    #L7:
+    case #C9:
+      {
+        core::print("is ios");
+        break #L4;
+      }
+    #L8:
+    case #C12:
+      {
+        core::print("is linux");
+        break #L4;
+      }
+    #L9:
+    case #C15:
+      {
+        core::print("is macos");
+        break #L4;
+      }
+    #L10:
+    case #C18:
+      {
+        core::print("is windows");
+        break #L4;
+      }
+  }
+}
+static method main(core::List<core::String> args) → dynamic {
+  if(args.{core::Iterable::isEmpty}{core::bool})
+    return;
+  final core::int i = core::int::parse(args.{core::List::[]}(0){(core::int) → core::String});
+  self::testAndroid(i);
+  self::testFuchsia(i);
+  self::testIOS(i);
+  self::testLinux(i);
+  self::testMacOS(i);
+  self::testWindows(i);
+  self::testSwitchStatements(i);
+  self::testPragma(i);
+  self::debugDefaultTestPlatform = #C3;
+  self::testConditionalPragma(i);
+  self::testConditionalPragmaWithAsserts(i);
+}
+constants  {
+  #C1 = 0
+  #C2 = "android"
+  #C3 = self::TestPlatform {index:#C1, _name:#C2}
+  #C4 = 1
+  #C5 = "fuchsia"
+  #C6 = self::TestPlatform {index:#C4, _name:#C5}
+  #C7 = 2
+  #C8 = "ios"
+  #C9 = self::TestPlatform {index:#C7, _name:#C8}
+  #C10 = 3
+  #C11 = "linux"
+  #C12 = self::TestPlatform {index:#C10, _name:#C11}
+  #C13 = 4
+  #C14 = "macos"
+  #C15 = self::TestPlatform {index:#C13, _name:#C14}
+  #C16 = 5
+  #C17 = "windows"
+  #C18 = self::TestPlatform {index:#C16, _name:#C17}
+  #C19 = <self::TestPlatform>[#C3, #C6, #C9, #C12, #C15, #C18]
+  #C20 = false
+  #C21 = true
+  #C22 = "\\"
+  #C23 = "vm:platform-const"
+  #C24 = null
+  #C25 = core::pragma {name:#C23, options:#C24}
+  #C26 = "vm:platform-const-if"
+  #C27 = core::pragma {name:#C26, options:#C21}
+  #C28 = core::pragma {name:#C26, options:#C20}
+}
diff --git a/runtime/docs/pragmas.md b/runtime/docs/pragmas.md
index 4e274b4..0d853b7 100644
--- a/runtime/docs/pragmas.md
+++ b/runtime/docs/pragmas.md
@@ -15,6 +15,7 @@
 | `vm:invisible` | Allows to mark a function as invisible so it will not appear on stack traces. |
 | `vm:always-consider-inlining` | Marks a function which particularly benefits from inlining and specialization in context of the caller (for example, when concrete types of arguments are known). Inliner will not give up after one failed inlining attempt and will continue trying to inline this function. |
 | `vm:platform-const` | Marks a static getter or a static field with an initializer where the getter body or field initializer evaluates to a constant value if the target operating system is known. |
+| `vm:platform-const-if` | Like `vm:platform-const`, but takes a boolean argument and constant evaluation of the annotated member is only performed if the argument const evaluates to true. |
 | `weak-tearoff-reference` | [Declaring a static weak reference intrinsic method.](compiler/pragmas_recognized_by_compiler.md#declaring-a-static-weak-reference-intrinsic-method) |
 | `vm:isolate-unsendable` | Marks a class, instances of which won't be allowed to be passed through ports or sent between isolates. |
 | `vm:awaiter-link` | [Specifying variable to follow for awaiter stack unwinding](awaiter_stack_traces.md) |