From 21e078a44a3147371004c4d87aed396264ee5748 Mon Sep 17 00:00:00 2001 From: Colin Cross Date: Mon, 16 Mar 2015 10:57:54 -0700 Subject: [PATCH] Document subtle behavior in createVariations createVariations relies on reusing the logicModule for the first variant in order to replace the original module in the global module map, which prevents leaving old split modules around in the global module map. Add comments to explain the behavior. Change-Id: Ia06d7fa4bc777e807241996d4e8bf977e641d741 --- context.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/context.go b/context.go index cee434c..c697556 100644 --- a/context.go +++ b/context.go @@ -734,6 +734,8 @@ func (c *Context) createVariations(origModule *moduleInfo, mutatorName string, if i == 0 { // Reuse the existing module for the first new variant + // This both saves creating a new module, and causes the insertion in c.moduleInfo below + // with logicModule as the key to replace the original entry in c.moduleInfo newLogicModule = origModule.logicModule newProperties = origModule.moduleProperties } else { @@ -774,6 +776,10 @@ func (c *Context) createVariations(origModule *moduleInfo, mutatorName string, } newModules = append(newModules, newModule) + + // Insert the new variant into the global module map. If this is the first variant then + // it reuses logicModule from the original module, which causes this to replace the + // original module in the global module map. c.moduleInfo[newModule.logicModule] = newModule newErrs := c.convertDepsToVariation(newModule, mutatorName, variationName)