| OLD | NEW |
| 1 // Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 library fasta.problems; | 5 library fasta.problems; |
| 6 | 6 |
| 7 import 'compiler_context.dart' show CompilerContext; |
| 8 |
| 7 import 'messages.dart' | 9 import 'messages.dart' |
| 8 show | 10 show |
| 9 Message, | 11 Message, |
| 10 deprecated_format, | |
| 11 templateInternalProblemUnexpected, | 12 templateInternalProblemUnexpected, |
| 12 templateInternalProblemUnhandled, | 13 templateInternalProblemUnhandled, |
| 13 templateInternalProblemUnimplemented, | 14 templateInternalProblemUnimplemented, |
| 14 templateInternalProblemUnsupported; | 15 templateInternalProblemUnsupported; |
| 15 | 16 |
| 17 import 'severity.dart' show Severity; |
| 18 |
| 16 /// Used to report an internal error. | 19 /// Used to report an internal error. |
| 17 /// | 20 /// |
| 18 /// Internal errors should be avoided as best as possible, but are preferred | 21 /// Internal errors should be avoided as best as possible, but are preferred |
| 19 /// over assertion failures. The message should start with an upper-case letter | 22 /// over assertion failures. The message should start with an upper-case letter |
| 20 /// and contain a short description that may help a developer debug the issue. | 23 /// and contain a short description that may help a developer debug the issue. |
| 21 /// This method should be called instead of using `throw`, as this allows us to | 24 /// This method should be called instead of using `throw`, as this allows us to |
| 22 /// ensure that there are no throws anywhere else in the codebase. | 25 /// ensure that there are no throws anywhere else in the codebase. |
| 23 /// | 26 /// |
| 24 /// Before printing the message, the string `"Internal error: "` is prepended. | 27 /// Before printing the message, the string `"Internal error: "` is prepended. |
| 25 dynamic internalProblem(Message message, int charOffset, Uri uri) { | 28 dynamic internalProblem(Message message, int charOffset, Uri uri) { |
| 26 String text = "Internal error: ${message.message}"; | 29 throw CompilerContext.current |
| 27 if (message.tip != null) { | 30 .format(message.withLocation(uri, charOffset), Severity.internalProblem); |
| 28 text += "\n${message.tip}"; | |
| 29 } | |
| 30 if (uri == null && charOffset == -1) { | |
| 31 throw text; | |
| 32 } else { | |
| 33 throw deprecated_format(uri, charOffset, text); | |
| 34 } | |
| 35 } | 31 } |
| 36 | 32 |
| 37 dynamic unimplemented(String what, [int charOffset = -1, Uri uri = null]) { | 33 dynamic unimplemented(String what, [int charOffset = -1, Uri uri = null]) { |
| 38 return internalProblem( | 34 return internalProblem( |
| 39 templateInternalProblemUnimplemented.withArguments(what), | 35 templateInternalProblemUnimplemented.withArguments(what), |
| 40 charOffset, | 36 charOffset, |
| 41 uri); | 37 uri); |
| 42 } | 38 } |
| 43 | 39 |
| 44 dynamic unhandled(String what, String where, int charOffset, Uri uri) { | 40 dynamic unhandled(String what, String where, int charOffset, Uri uri) { |
| 45 return internalProblem( | 41 return internalProblem( |
| 46 templateInternalProblemUnhandled.withArguments(what, where), | 42 templateInternalProblemUnhandled.withArguments(what, where), |
| 47 charOffset, | 43 charOffset, |
| 48 uri); | 44 uri); |
| 49 } | 45 } |
| 50 | 46 |
| 51 dynamic unexpected(String expected, String actual, int charOffset, Uri uri) { | 47 dynamic unexpected(String expected, String actual, int charOffset, Uri uri) { |
| 52 return internalProblem( | 48 return internalProblem( |
| 53 templateInternalProblemUnexpected.withArguments(expected, actual), | 49 templateInternalProblemUnexpected.withArguments(expected, actual), |
| 54 charOffset, | 50 charOffset, |
| 55 uri); | 51 uri); |
| 56 } | 52 } |
| 57 | 53 |
| 58 dynamic unsupported(String operation, int charOffset, Uri uri) { | 54 dynamic unsupported(String operation, int charOffset, Uri uri) { |
| 59 return internalProblem( | 55 return internalProblem( |
| 60 templateInternalProblemUnsupported.withArguments(operation), | 56 templateInternalProblemUnsupported.withArguments(operation), |
| 61 charOffset, | 57 charOffset, |
| 62 uri); | 58 uri); |
| 63 } | 59 } |
| OLD | NEW |