Skip to content
Browse files

Allow stubs in roles to be satisfied by inheritance

  • Loading branch information...
1 parent 4446002 commit dd7ae96af90a9b473775f3fdd8209974f530298f @sorear committed Jan 5, 2012
Showing with 22 additions and 12 deletions.
  1. +1 −1 lib/Kernel.cs
  2. +19 −11 lib/ObjModel.cs
  3. +2 −0 t/spectest.data
View
2 lib/Kernel.cs
@@ -5533,7 +5533,7 @@ internal class MMDCandidate : MultiCandidate {
}
foreach (var name in requirements) {
- if (role_methods.ContainsKey(name.Key) || class_methods.Contains(name.Key)) continue;
+ if (role_methods.ContainsKey(name.Key) || class_methods.Contains(name.Key) || (name.Key.v1 == 0 && cls.FindMethod(name.Key.v2) != null)) continue;
throw new NieczaException(MethodSlot(name.Key) + " must be implemented by '" + cls.name + "' because it is required by role '" + name.Value + "'");
}
View
30 lib/ObjModel.cs
@@ -594,6 +594,22 @@ public class DispatchSet {
}
}
+ string ComputeMRO() {
+ string err;
+ STable[][] lists = new STable[superclasses.Count + 2][];
+ lists[0] = new STable[] { stable };
+ lists[superclasses.Count + 1] = superclasses.ToArray();
+ for (int i = 0; i < superclasses.Count; i++)
+ lists[i+1] = superclasses[i].mo.mro;
+
+ List<STable> nmro = new List<STable>();
+ err = C3Merge(nmro, lists);
+ if (err != null)
+ return "C3 MRO generation failed for " + stable.name + ": " + err;
+ SetMRO(nmro.ToArray());
+ return null;
+ }
+
public string Compose() {
if (isComposed || type == PACKAGE || type == MODULE) {
isComposed = true;
@@ -621,6 +637,8 @@ public class DispatchSet {
}
if (local_roles.Count > 0) {
+ if ((err = ComputeMRO()) != null) return err;
+ Revalidate();
Kernel.ApplyRoleToClass(stable, local_roles.ToArray());
}
@@ -629,17 +647,7 @@ public class DispatchSet {
Kernel.AnyMO);
}
- STable[][] lists = new STable[superclasses.Count + 2][];
- lists[0] = new STable[] { stable };
- lists[superclasses.Count + 1] = superclasses.ToArray();
- for (int i = 0; i < superclasses.Count; i++)
- lists[i+1] = superclasses[i].mo.mro;
-
- List<STable> nmro = new List<STable>();
- err = C3Merge(nmro, lists);
- if (err != null)
- return "C3 MRO generation failed for " + stable.name + ": " + err;
- SetMRO(nmro.ToArray());
+ if ((err = ComputeMRO()) != null) return err;
List<string> all_slot_l = new List<string>();
foreach (STable m in mro)
View
2 t/spectest.data
@@ -346,6 +346,8 @@ S13-type-casting/methods.t
S14-roles/attributes.t
S14-roles/composition.t
S14-roles/lexical.t
+S14-roles/stubs.t
+S14-roles/submethods.t
S16-filehandles/filetest.t
S16-filehandles/io.t
S16-filehandles/io_in_for_loops.t

0 comments on commit dd7ae96

Please sign in to comment.
Something went wrong with that request. Please try again.