diff --git a/src/zc/buildout/buildout.py b/src/zc/buildout/buildout.py
index 5d8efa929ae9bc1c1009d5a6aed908f20060ab9a..796b60d5aba3c95c385192a40485fe862c190ad5 100644
--- a/src/zc/buildout/buildout.py
+++ b/src/zc/buildout/buildout.py
@@ -1083,7 +1083,7 @@ class Options(DictMixin):
             self._raw = self._do_extend_raw(name, self._raw, [])
 
         # force substitutions
-        for k, v in list(self._raw.items()):
+        for k, v in sorted(self._raw.items()):
             if '${' in v:
                 self._dosub(k, v)
 
diff --git a/src/zc/buildout/tests.py b/src/zc/buildout/tests.py
index f914e4832fa1a526c142cdf7970663057f6a112a..5302d718a596f441cced138b43f746f238e4aec0 100644
--- a/src/zc/buildout/tests.py
+++ b/src/zc/buildout/tests.py
@@ -137,10 +137,10 @@ It is an error to create a variable-reference cycle:
       Initializing.
       Getting section buildout.
       Initializing section buildout.
+      Getting option buildout:x.
       Getting option buildout:y.
       Getting option buildout:z.
       Getting option buildout:x.
-      Getting option buildout:y.
     Error: Circular reference in substitutions.
 
 It is an error to use funny characters in variable refereces: