[VM] Handle [VariableGet]s for parameters/let variables differently than other const variables

Change-Id: I10e74b7535936a62964cc4f00aac2572552b31d7
Reviewed-on: https://dart-review.googlesource.com/62064
Reviewed-by: Vyacheslav Egorov <vegorov@google.com>
Commit-Queue: Martin Kustermann <kustermann@google.com>
diff --git a/pkg/kernel/lib/transformations/constants.dart b/pkg/kernel/lib/transformations/constants.dart
index 212d6e8..54d62ed 100644
--- a/pkg/kernel/lib/transformations/constants.dart
+++ b/pkg/kernel/lib/transformations/constants.dart
@@ -911,18 +911,19 @@
     // TODO(kustermann): The heuristic of allowing all [VariableGet]s on [Let]
     // variables might allow more than it should.
     final VariableDeclaration variable = node.variable;
-    if (!variable.isConst &&
-        !_isFormalParameter(variable) &&
-        variable.parent is! Let) {
-      throw new Exception('The front-end should ensure we do not encounter a '
-          'variable get of a non-const variable.');
+    if (variable.parent is Let || _isFormalParameter(variable)) {
+      final Constant constant = env.lookupVariable(node.variable);
+      if (constant == null) {
+        errorReporter.nonConstantVariableGet(contextChain, node, variable.name);
+        throw const _AbortCurrentEvaluation();
+      }
+      return constant;
     }
-    final Constant constant = env.lookupVariable(node.variable);
-    if (constant == null) {
-      errorReporter.nonConstantVariableGet(contextChain, node, variable.name);
-      throw const _AbortCurrentEvaluation();
+    if (variable.isConst) {
+      return evaluate(variable.initializer);
     }
-    return constant;
+    throw new Exception('The front-end should ensure we do not encounter a '
+        'variable get of a non-const variable.');
   }
 
   visitStaticGet(StaticGet node) {
diff --git a/pkg/vm/lib/kernel_front_end.dart b/pkg/vm/lib/kernel_front_end.dart
index b5ff2d5..610f2a1 100644
--- a/pkg/vm/lib/kernel_front_end.dart
+++ b/pkg/vm/lib/kernel_front_end.dart
@@ -346,7 +346,7 @@
   }
 
   getFileOffset(TreeNode node) {
-    while (node.fileOffset == TreeNode.noOffset) {
+    while (node?.fileOffset == TreeNode.noOffset) {
       node = node.parent;
     }
     return node == null ? TreeNode.noOffset : node.fileOffset;