Fix rare crash in type inference engine

Before this CL, running fasta compile on these 3 tests would make it
crash in type inference because the enclosingClass on a constrcutor
is null:

tests/language_2/const_error_multiply_initialized_test.dart
tests/language_2/constructor_duplicate_final_test.dart
tests/language_2/field3_test.dart

Note that these tests are all multi-tests and they are here run
unprocessed. The compiler crashes only after issuing errors.
The crash likely happens because of multiple definitions of
constructors with the same name.

This is a cut-down version that crashed prior to this CL:

```
class C {
  final d;

  C() {}
  C(this.d) {}
}
```

Fixes #35258.

Change-Id: I350c55428932ef0ae76f78875177b08acf95cdfc
Reviewed-on: https://dart-review.googlesource.com/c/85363
Reviewed-by: Peter von der Ahé <ahe@google.com>
Commit-Queue: Jens Johansen <jensj@google.com>
diff --git a/pkg/front_end/lib/src/fasta/source/source_class_builder.dart b/pkg/front_end/lib/src/fasta/source/source_class_builder.dart
index 1517023..206b383 100644
--- a/pkg/front_end/lib/src/fasta/source/source_class_builder.dart
+++ b/pkg/front_end/lib/src/fasta/source/source_class_builder.dart
@@ -130,6 +130,7 @@
           }
         } else if (declaration is KernelFunctionBuilder) {
           Member function = declaration.build(library);
+          function.parent = cls;
           if (!declaration.isPatch && declaration.next == null) {
             cls.addMember(function);
           }
diff --git a/pkg/front_end/testcases/legacy.status b/pkg/front_end/testcases/legacy.status
index 42f9157..c4c996e 100644
--- a/pkg/front_end/testcases/legacy.status
+++ b/pkg/front_end/testcases/legacy.status
@@ -107,6 +107,7 @@
 regress/issue_34225: RuntimeError
 regress/issue_34563: RuntimeError # Test execution after recovery
 regress/issue_35177: RuntimeError
+regress/issue_35258: RuntimeError # Expected
 regress/issue_35259: RuntimeError # Expected
 regress/issue_35260: RuntimeError # Expected
 runtime_checks/implicit_downcast_constructor_initializer: RuntimeError # Test exercises strong mode semantics
diff --git a/pkg/front_end/testcases/regress/issue_35258.dart b/pkg/front_end/testcases/regress/issue_35258.dart
new file mode 100644
index 0000000..486fae4
--- /dev/null
+++ b/pkg/front_end/testcases/regress/issue_35258.dart
@@ -0,0 +1,14 @@
+// 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.
+
+main() {
+  new C(42);
+}
+
+class C {
+  final d;
+
+  C() {}
+  C(this.d) {}
+}
diff --git a/pkg/front_end/testcases/regress/issue_35258.dart.legacy.expect b/pkg/front_end/testcases/regress/issue_35258.dart.legacy.expect
new file mode 100644
index 0000000..0707a98
--- /dev/null
+++ b/pkg/front_end/testcases/regress/issue_35258.dart.legacy.expect
@@ -0,0 +1,41 @@
+// Formatted problems:
+//
+// pkg/front_end/testcases/regress/issue_35258.dart:13:3: Error: 'C' is already declared in this scope.
+//   C(this.d) {}
+//   ^
+// pkg/front_end/testcases/regress/issue_35258.dart:12:3: Context: Previous declaration of 'C'.
+//   C() {}
+//   ^
+//
+// pkg/front_end/testcases/regress/issue_35258.dart:6:7: Error: Can't use 'C' because it is declared more than once.
+//   new C(42);
+//       ^
+//
+// pkg/front_end/testcases/regress/issue_35258.dart:10:9: Error: Final field 'd' is not initialized.
+// Try to initialize the field in the declaration or in every constructor.
+//   final d;
+//         ^
+
+// Unhandled errors:
+//
+// pkg/front_end/testcases/regress/issue_35258.dart:13:3: Error: 'C' is already declared in this scope.
+//   C(this.d) {}
+//   ^
+//
+// pkg/front_end/testcases/regress/issue_35258.dart:10:9: Error: Final field 'd' is not initialized.
+// Try to initialize the field in the declaration or in every constructor.
+//   final d;
+//         ^
+
+library;
+import self as self;
+import "dart:core" as core;
+
+class C extends core::Object {
+  final field dynamic d = null;
+  constructor •() → self::C
+    : super core::Object::•() {}
+}
+static method main() → dynamic {
+  let dynamic _ = null in throw new core::NoSuchMethodError::withInvocation(null, new core::_InvocationMirror::_withType(#C, 32, const <core::Type>[], core::List::unmodifiable<dynamic>(<dynamic>[42]), core::Map::unmodifiable<core::Symbol, dynamic>(const <core::Symbol, dynamic>{})));
+}
diff --git a/pkg/front_end/testcases/regress/issue_35258.dart.legacy.transformed.expect b/pkg/front_end/testcases/regress/issue_35258.dart.legacy.transformed.expect
new file mode 100644
index 0000000..15c4c7d
--- /dev/null
+++ b/pkg/front_end/testcases/regress/issue_35258.dart.legacy.transformed.expect
@@ -0,0 +1,23 @@
+// Unhandled errors:
+//
+// pkg/front_end/testcases/regress/issue_35258.dart:13:3: Error: 'C' is already declared in this scope.
+//   C(this.d) {}
+//   ^
+//
+// pkg/front_end/testcases/regress/issue_35258.dart:10:9: Error: Final field 'd' is not initialized.
+// Try to initialize the field in the declaration or in every constructor.
+//   final d;
+//         ^
+
+library;
+import self as self;
+import "dart:core" as core;
+
+class C extends core::Object {
+  final field dynamic d = null;
+  constructor •() → self::C
+    : super core::Object::•() {}
+}
+static method main() → dynamic {
+  let dynamic _ = null in throw new core::NoSuchMethodError::withInvocation(null, new core::_InvocationMirror::_withType(#C, 32, const <core::Type>[], core::List::unmodifiable<dynamic>(<dynamic>[42]), core::Map::unmodifiable<core::Symbol, dynamic>(const <core::Symbol, dynamic>{})));
+}
diff --git a/pkg/front_end/testcases/regress/issue_35258.dart.outline.expect b/pkg/front_end/testcases/regress/issue_35258.dart.outline.expect
new file mode 100644
index 0000000..6573c01
--- /dev/null
+++ b/pkg/front_end/testcases/regress/issue_35258.dart.outline.expect
@@ -0,0 +1,20 @@
+// Formatted problems:
+//
+// pkg/front_end/testcases/regress/issue_35258.dart:13:3: Error: 'C' is already declared in this scope.
+//   C(this.d) {}
+//   ^
+// pkg/front_end/testcases/regress/issue_35258.dart:12:3: Context: Previous declaration of 'C'.
+//   C() {}
+//   ^
+
+library;
+import self as self;
+import "dart:core" as core;
+
+class C extends core::Object {
+  final field dynamic d;
+  constructor •() → self::C
+    ;
+}
+static method main() → dynamic
+  ;
diff --git a/pkg/front_end/testcases/regress/issue_35258.dart.strong.expect b/pkg/front_end/testcases/regress/issue_35258.dart.strong.expect
new file mode 100644
index 0000000..ee9cdb0
--- /dev/null
+++ b/pkg/front_end/testcases/regress/issue_35258.dart.strong.expect
@@ -0,0 +1,43 @@
+// Formatted problems:
+//
+// pkg/front_end/testcases/regress/issue_35258.dart:13:3: Error: 'C' is already declared in this scope.
+//   C(this.d) {}
+//   ^
+// pkg/front_end/testcases/regress/issue_35258.dart:12:3: Context: Previous declaration of 'C'.
+//   C() {}
+//   ^
+//
+// pkg/front_end/testcases/regress/issue_35258.dart:6:7: Error: Can't use 'C' because it is declared more than once.
+//   new C(42);
+//       ^
+//
+// pkg/front_end/testcases/regress/issue_35258.dart:10:9: Error: Final field 'd' is not initialized.
+// Try to initialize the field in the declaration or in every constructor.
+//   final d;
+//         ^
+
+// Unhandled errors:
+//
+// pkg/front_end/testcases/regress/issue_35258.dart:13:3: Error: 'C' is already declared in this scope.
+//   C(this.d) {}
+//   ^
+//
+// pkg/front_end/testcases/regress/issue_35258.dart:10:9: Error: Final field 'd' is not initialized.
+// Try to initialize the field in the declaration or in every constructor.
+//   final d;
+//         ^
+
+library;
+import self as self;
+import "dart:core" as core;
+
+class C extends core::Object {
+  final field dynamic d = null;
+  constructor •() → self::C
+    : super core::Object::•() {}
+}
+static method main() → dynamic {
+  invalid-expression "pkg/front_end/testcases/regress/issue_35258.dart:6:7: Error: Can't use 'C' because it is declared more than once.
+  new C(42);
+      ^";
+}
diff --git a/pkg/front_end/testcases/regress/issue_35258.dart.strong.transformed.expect b/pkg/front_end/testcases/regress/issue_35258.dart.strong.transformed.expect
new file mode 100644
index 0000000..dc46e1b
--- /dev/null
+++ b/pkg/front_end/testcases/regress/issue_35258.dart.strong.transformed.expect
@@ -0,0 +1,25 @@
+// Unhandled errors:
+//
+// pkg/front_end/testcases/regress/issue_35258.dart:13:3: Error: 'C' is already declared in this scope.
+//   C(this.d) {}
+//   ^
+//
+// pkg/front_end/testcases/regress/issue_35258.dart:10:9: Error: Final field 'd' is not initialized.
+// Try to initialize the field in the declaration or in every constructor.
+//   final d;
+//         ^
+
+library;
+import self as self;
+import "dart:core" as core;
+
+class C extends core::Object {
+  final field dynamic d = null;
+  constructor •() → self::C
+    : super core::Object::•() {}
+}
+static method main() → dynamic {
+  invalid-expression "pkg/front_end/testcases/regress/issue_35258.dart:6:7: Error: Can't use 'C' because it is declared more than once.
+  new C(42);
+      ^";
+}
diff --git a/pkg/front_end/testcases/strong.status b/pkg/front_end/testcases/strong.status
index 1a7f335..4efd9ed 100644
--- a/pkg/front_end/testcases/strong.status
+++ b/pkg/front_end/testcases/strong.status
@@ -133,6 +133,7 @@
 regress/issue_34225: RuntimeError
 regress/issue_34563: RuntimeError # Test execution after recovery
 regress/issue_35177: RuntimeError
+regress/issue_35258: RuntimeError # Expected
 regress/issue_35259: RuntimeError # Expected
 regress/issue_35260: RuntimeError # Expected
 runtime_checks_new/contravariant_generic_return_with_compound_assign_implicit_downcast: RuntimeError
diff --git a/tests/language_2/regress_35258_test.dart b/tests/language_2/regress_35258_test.dart
new file mode 100644
index 0000000..d875985
--- /dev/null
+++ b/tests/language_2/regress_35258_test.dart
@@ -0,0 +1,14 @@
+// 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.
+
+main() {
+  new C(42);
+}
+
+class C {
+  final d;
+
+  C() {} //# 01: compile-time error
+  C(this.d) {}
+}