dart-sdk/tests/language_2/enum_initialization_near_stack_overflow_test.dart
Ryan Macnak 30896b87f1 [vm] Fix crash when enum initialization hits a stack overflow.
Give the compiler more headroom.

Have the simulators and interpreters distinguish between the true stack limit and the limit for trigger an overflow exception.

Bug: https://github.com/dart-lang/sdk/issues/35224
Bug: https://github.com/flutter/flutter/issues/25041
Change-Id: I048d73b649b4ce1f3d9b5a33d898ee9cfe54f6ca
Reviewed-on: https://dart-review.googlesource.com/c/86821
Reviewed-by: Aart Bik <ajcbik@google.com>
Reviewed-by: Régis Crelier <regis@google.com>
Commit-Queue: Ryan Macnak <rmacnak@google.com>
2018-12-10 23:40:21 +00:00

33 lines
783 B
Dart

// Copyright (c) 2018, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
// https://github.com/flutter/flutter/issues/25041
// This test may produce a compile time exception from stack overflow during
// enum initialization or succeed in enum initialization depending on exactly
// how much stack is left and used by the compiler. It should never crash nor
// produce a runtime exception.
enum Fruit {
apple,
banana,
}
getFruit() => Fruit.apple;
recurse() {
try {
recurse();
} catch (e, st) {
print("$e ${getFruit()}");
}
}
main() {
try {
recurse();
} on StackOverflowError catch (e) {
// Swallow.
}
}