bool DoDefineBaseType ()
{
iface_exprs = ResolveBaseTypes (out base_type_expr);
bool set_base_type;
if (IsPartialPart) {
set_base_type = false;
if (base_type_expr != null) {
if (PartialContainer.base_type_expr != null && PartialContainer.base_type != base_type) {
Report.SymbolRelatedToPreviousError (base_type_expr.Location, "");
Report.Error (263, Location,
"Partial declarations of `{0}' must not specify different base classes",
GetSignatureForError ());
} else {
PartialContainer.base_type_expr = base_type_expr;
PartialContainer.base_type = base_type;
set_base_type = true;
}
}
if (iface_exprs != null) {
if (PartialContainer.iface_exprs == null)
PartialContainer.iface_exprs = iface_exprs;
else {
var ifaces = new List<TypeSpec> (PartialContainer.iface_exprs);
foreach (var iface_partial in iface_exprs) {
if (ifaces.Contains (iface_partial))
continue;
ifaces.Add (iface_partial);
}
PartialContainer.iface_exprs = ifaces.ToArray ();
}
}
PartialContainer.members.AddRange (members);
if (containers != null) {
if (PartialContainer.containers == null)
PartialContainer.containers = new List<TypeContainer> ();
PartialContainer.containers.AddRange (containers);
}
if (PrimaryConstructorParameters != null) {
if (PartialContainer.PrimaryConstructorParameters != null) {
Report.Error (8036, Location, "Only one part of a partial type can declare primary constructor parameters");
} else {
PartialContainer.PrimaryConstructorParameters = PrimaryConstructorParameters;
}
}
members_defined = members_defined_ok = true;
caching_flags |= Flags.CloseTypeCreated;
} else {
set_base_type = true;
}
var cycle = CheckRecursiveDefinition (this);
if (cycle != null) {
Report.SymbolRelatedToPreviousError (cycle);
if (this is Interface) {
Report.Error (529, Location,
"Inherited interface `{0}' causes a cycle in the interface hierarchy of `{1}'",
GetSignatureForError (), cycle.GetSignatureForError ());
iface_exprs = null;
PartialContainer.iface_exprs = null;
} else {
Report.Error (146, Location,
"Circular base class dependency involving `{0}' and `{1}'",
GetSignatureForError (), cycle.GetSignatureForError ());
base_type = null;
PartialContainer.base_type = null;
}
}
if (iface_exprs != null) {
if (!PrimaryConstructorBaseArgumentsStart.IsNull) {
Report.Error (8049, PrimaryConstructorBaseArgumentsStart, "Implemented interfaces cannot have arguments");
}
foreach (var iface_type in iface_exprs) {
// Prevents a crash, the interface might not have been resolved: 442144
if (iface_type == null)
continue;
if (!spec.AddInterfaceDefined (iface_type))
continue;
TypeBuilder.AddInterfaceImplementation (iface_type.GetMetaInfo ());
}
}
if (Kind == MemberKind.Interface) {
spec.BaseType = Compiler.BuiltinTypes.Object;
return true;
}
if (set_base_type) {
SetBaseType ();
}
//
// Base type of partial container has to be resolved before we
// resolve any nested types of the container. We need to know
// partial parts because the base type can be specified in file
// defined after current container
//
if (class_partial_parts != null) {
foreach (var pp in class_partial_parts) {
if (pp.PrimaryConstructorBaseArguments != null)
PrimaryConstructorBaseArguments = pp.PrimaryConstructorBaseArguments;
pp.DoDefineBaseType ();
}
}
return true;
}