Chromium Code Reviews| Index: pkg/front_end/lib/src/fasta/kernel/fasta_accessors.dart |
| diff --git a/pkg/front_end/lib/src/fasta/kernel/fasta_accessors.dart b/pkg/front_end/lib/src/fasta/kernel/fasta_accessors.dart |
| index d204b9fd870be049e2848be9a5c52898ebe28611..ad4e5cdca377036c2b06abf9b2900012845a161f 100644 |
| --- a/pkg/front_end/lib/src/fasta/kernel/fasta_accessors.dart |
| +++ b/pkg/front_end/lib/src/fasta/kernel/fasta_accessors.dart |
| @@ -39,7 +39,7 @@ import 'frontend_accessors.dart' as kernel |
| import 'kernel_builder.dart' |
| show Builder, KernelClassBuilder, PrefixBuilder, TypeDeclarationBuilder; |
| -import '../names.dart' show callName; |
| +import '../names.dart' show callName, lengthName; |
| abstract class BuilderHelper { |
| Uri get uri; |
| @@ -90,6 +90,8 @@ abstract class BuilderHelper { |
| dynamic addCompileTimeError(int charOffset, String message, {bool silent}); |
| + bool isIdentical(Member member); |
| + |
| Expression buildMethodInvocation( |
| Expression receiver, Name name, Arguments arguments, int offset, |
| {bool isConstantExpression, bool isNullAware}); |
| @@ -138,6 +140,10 @@ abstract class FastaAccessor implements Accessor { |
| send.arguments, offsetForToken(send.token), |
| isNullAware: isNullAware); |
| } else { |
| + if (helper.constantExpressionRequired && send.name != lengthName) { |
| + helper.addCompileTimeError( |
| + offsetForToken(token), "Not a constant expression."); |
| + } |
| return PropertyAccessor.make(helper, send.token, buildSimpleRead(), |
| send.name, null, null, isNullAware); |
| } |
| @@ -296,6 +302,11 @@ class ThisAccessor extends FastaAccessor { |
| offsetForToken(token)); |
| return isSuper ? helper.toSuperMethodInvocation(result) : result; |
| } else { |
| + if (!isInitializer && helper.constantExpressionRequired) { |
| + // TODO(ahe): Remove this? |
|
ahe
2017/05/30 09:56:28
I've invested the 50-60 minutes it took to answer
|
| + helper.addCompileTimeError( |
| + offsetForToken(token), "Not a constant expression."); |
| + } |
| if (isSuper) { |
| Member getter = helper.lookupSuperMember(send.name); |
| Member setter = helper.lookupSuperMember(send.name, isSetter: true); |
| @@ -692,9 +703,15 @@ class StaticAccessor extends kernel.StaticAccessor with FastaAccessor { |
| String get plainNameForRead => (readTarget ?? writeTarget).name.name; |
| Expression doInvocation(int offset, Arguments arguments) { |
| + if (helper.constantExpressionRequired && !helper.isIdentical(readTarget)) { |
| + helper.addCompileTimeError(offset, "Not a constant expression."); |
| + } |
| if (readTarget == null || isFieldOrGetter(readTarget)) { |
| return helper.buildMethodInvocation(buildSimpleRead(), callName, |
| - arguments, offset + (readTarget?.name?.name?.length ?? 0)); |
| + arguments, offset + (readTarget?.name?.name?.length ?? 0), |
| + // This isn't a constant expression, but we have checked if a |
| + // constant expression error should be emitted already. |
| + isConstantExpression: true); |
| } else { |
| return helper.buildStaticInvocation(readTarget, arguments) |
| ..fileOffset = offset; |
| @@ -713,9 +730,15 @@ class SuperPropertyAccessor extends kernel.SuperPropertyAccessor |
| String get plainNameForRead => name.name; |
| Expression doInvocation(int offset, Arguments arguments) { |
| + if (helper.constantExpressionRequired) { |
| + helper.addCompileTimeError(offset, "Not a constant expression."); |
| + } |
| if (getter == null || isFieldOrGetter(getter)) { |
| return helper.buildMethodInvocation( |
| - buildSimpleRead(), callName, arguments, offset); |
| + buildSimpleRead(), callName, arguments, offset, |
| + // This isn't a constant expression, but we have checked if a |
| + // constant expression error should be emitted already. |
| + isConstantExpression: true); |
| } else { |
| return new DirectMethodInvocation(new ThisExpression(), getter, arguments) |
| ..fileOffset = offset; |