Browse Source

[tests] define interface relationships too

Simon Krajewski 6 years ago
parent
commit
7cfcd2d397
1 changed files with 39 additions and 4 deletions
  1. 39 4
      tests/unit/src/unit/TestFieldVariance.hx

+ 39 - 4
tests/unit/src/unit/TestFieldVariance.hx

@@ -18,20 +18,55 @@ private typedef NullField = {
 	var aField(default, null):Int;
 }
 
-private class PublicFieldClass {
+private interface PublicFieldInterface {
 	public var aField:Int;
 }
 
+private interface FinalFieldInterface {
+	public final aField:Int;
+}
+
+private interface NeverFieldInterface {
+	public var aField(default, never):Int;
+}
+
+private interface NullFieldInterface {
+	public var aField(default, null):Int;
+}
+
+private class PublicFieldClass
+	implements PublicFieldInterface // ok, same
+	implements NullFieldInterface // ok, narrowing access
+	implements NeverFieldInterface // ok, narrowing access
+	/* implements FinalFieldInterface */ // not ok, final invariance
+	{
+	public var aField:Int;
+}
 
-private class FinalFieldClass {
+private class FinalFieldClass
+	implements FinalFieldInterface // ok,same
+	implements NeverFieldInterface // ok, no write-access
+	implements NullFieldInterface // ok, no write-access
+	/* implements PublicFieldInterface */ // not ok, final invariance
+	{
 	public final aField:Int = 0;
 }
 
-private class NeverFieldClass {
+private class NeverFieldClass
+	implements NeverFieldInterface // ok, same
+	implements NullFieldInterface // ok, no write-access
+	/* implements PublicFieldInterface */ // not ok, widening access
+	/* implements FinalFieldInterface */ // not ok, final invariance
+	{
 	public var aField(default, never):Int;
 }
 
-private class NullFieldClass {
+private class NullFieldClass
+	implements NullFieldInterface // ok, same
+	implements NeverFieldInterface // ok, no write-access
+	/* implements PublicFieldInterface */ // not ok, widening access
+	/* implements FinalFieldInterface */ // not ok, final invariance
+	{
 	public var aField(default, null):Int;
 }