Skip to content

Commit

Permalink
Merge branch 'version_10_0_0_master' of github.com:ChilliCream/hotcho…
Browse files Browse the repository at this point in the history
…colate into version_10_0_0_master
  • Loading branch information
michaelstaib committed Mar 4, 2020
2 parents 0d6af95 + 31e9b46 commit 0a22234
Showing 1 changed file with 36 additions and 30 deletions.
66 changes: 36 additions & 30 deletions src/Core/Types/Configuration/TypeInitializer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -187,50 +187,56 @@ private void MergeTypeExtensions(DiscoveredTypes discoveredTypes)
.Where(t => t.IsNamedType)
.ToList();

foreach (RegisteredType extension in extensions)
foreach (IGrouping<NameString, RegisteredType> group in
extensions.GroupBy(t => t.Type.Name))
{
RegisteredType type = types.FirstOrDefault(t =>
t.Type.Name.Equals(extension.Type.Name));
t.Type.Name.Equals(group.Key));

if (type != null
&& extension.Type is INamedTypeExtensionMerger m
&& type.Type is INamedType n)
if (type != null && type.Type is INamedType targetType)
{
// merge
CompletionContext context = _completionContext[extension];
context.Status = TypeStatus.Named;
MergeTypeExtension(context, m, n);

// update dependencies
context = _completionContext[type];
type = type.AddDependencies(extension.Dependencies);
discoveredTypes.UpdateType(type);
_completionContext[type] = context;
CopyAlternateNames(_completionContext[extension], context);
MergeTypeExtension(discoveredTypes, group, type, targetType);
}
}

discoveredTypes.RebuildTypeSet();
}
}

private static void MergeTypeExtension(
ICompletionContext context,
INamedTypeExtensionMerger extension,
INamedType type)
private void MergeTypeExtension(
DiscoveredTypes discoveredTypes,
IEnumerable<RegisteredType> extensions,
RegisteredType type,
INamedType targetType)
{
if (extension.Kind != type.Kind)
foreach (RegisteredType extension in extensions)
{
throw new SchemaException(SchemaErrorBuilder.New()
.SetMessage(string.Format(
CultureInfo.InvariantCulture,
TypeResources.TypeInitializer_Merge_KindDoesNotMatch,
type.Name))
.SetTypeSystemObject((ITypeSystemObject)type)
.Build());
}
if (extension.Type is INamedTypeExtensionMerger m)
{
if (m.Kind != targetType.Kind)
{
throw new SchemaException(SchemaErrorBuilder.New()
.SetMessage(string.Format(
CultureInfo.InvariantCulture,
TypeResources.TypeInitializer_Merge_KindDoesNotMatch,
targetType.Name))
.SetTypeSystemObject((ITypeSystemObject)targetType)
.Build());
}

extension.Merge(context, type);
// merge
CompletionContext context = _completionContext[extension];
context.Status = TypeStatus.Named;
m.Merge(context, targetType);

// update dependencies
context = _completionContext[type];
type = type.AddDependencies(extension.Dependencies);
discoveredTypes.UpdateType(type);
_completionContext[type] = context;
CopyAlternateNames(_completionContext[extension], context);
}
}
}

private static void CopyAlternateNames(
Expand Down

0 comments on commit 0a22234

Please sign in to comment.