[vm/bytecode] Set 'TypeEnvironment.thisType' when generating bytecode

This is needed for Expression.getStaticType() to work in certain
cases and improves recognition of int operations.

Change-Id: I80073a797a39ab5d6b3715940961a231e0a8ab10
Reviewed-on: https://dart-review.googlesource.com/c/78142
Auto-Submit: Alexander Markov <alexmarkov@google.com>
Commit-Queue: Zach Anderson <zra@google.com>
Reviewed-by: Zach Anderson <zra@google.com>
diff --git a/pkg/vm/lib/bytecode/gen_bytecode.dart b/pkg/vm/lib/bytecode/gen_bytecode.dart
index 3f13f06..9e3ea83 100644
--- a/pkg/vm/lib/bytecode/gen_bytecode.dart
+++ b/pkg/vm/lib/bytecode/gen_bytecode.dart
@@ -671,6 +671,9 @@
     parentFunction = null;
     isClosure = false;
     hasErrors = false;
+    if ((node is Procedure && !node.isStatic) || node is Constructor) {
+      typeEnvironment.thisType = enclosingClass.thisType;
+    }
     final isFactory = node is Procedure && node.isFactory;
     if (node.isInstanceMember || node is Constructor || isFactory) {
       if (enclosingClass.typeParameters.isNotEmpty) {
@@ -752,6 +755,7 @@
           cp, asm.bytecode, asm.exceptionsTable, nullableFields, closures);
     }
 
+    typeEnvironment.thisType = null;
     enclosingClass = null;
     enclosingMember = null;
     enclosingFunction = null;