Subject: [netmod] defaults and union

From: Ladislav Lhotka <[email-masked]>
Date: Thu, 11 Jun 2009 08:43:15 +0200

Hi,

derived types with specified defaults may cause an ambiguity if they are
used in a union:

  typedef foo {
    type string;
    default "foo";
  }
  typedef bar {
    type string;
    default "bar";
  }
  typedef foo-bar {
    type union {
      type foo;
      type bar;
    }
  }
  leaf foobar {
    type foo-bar;
  }

Now, the default value for leaf foobar can be either "foo" or "bar".

Lada

-- 
Ladislav Lhotka, CESNET
PGP Key ID: E74E8C0C

---

From: Martin Bjorklund <[email-masked]>
Date: Thu, 11 Jun 2009 14:21:28 +0200 (CEST)

Hi,

> Now, the default value for leaf foobar can be either "foo" or "bar".

Yes, I think we need to say that the default value is not inherited in
the case of a union.

/martin

---

From: Andy Bierman <[email-masked]>
Date: Thu, 11 Jun 2009 07:33:54 -0700

> Yes, I think we need to say that the default value is not inherited in

this is not very good.

What if the foobar typedef is itself used inside another
union type-stmt (could be in a leaf).  The typedef-default may
not be obvious to spot.

Of course, any default-stmt appearing in a leaf is going
to be used, regardless of this problem, so this special
case for union typedefs will be very confusing.

Union type statements are always processed in
schema order.  The default for foobar is always 'foo'.
So what's the problem?  Garbage in == Garbage out,
just like this:

    type union {
       type string;
       type uint32;   // will never get picked
    }

> /martin

Andy

---

From: Ladislav Lhotka <[email-masked]>
Date: Thu, 11 Jun 2009 18:08:21 +0200

>        type uint32;   // will never get picked

But what if you had

    type union {
        type string;
        type myuint;
    }
    typedef myuint {
        type uint32;
        default "42";
    }

Will such a leaf get the default from "myuint" even though this type is
never picked from the union as the leaf's type?

I'd rather support Martin's suggestion to ignore all typedef-based
defaults in union leafs.

Lada

-- 
Ladislav Lhotka, CESNET
PGP Key ID: E74E8C0C

---

From: Andy Bierman <[email-masked]>
Date: Thu, 11 Jun 2009 09:37:38 -0700

> I'd rather support Martin's suggestion to ignore all typedef-based

I don't, because it is confusing.
In your garbage example, you would get garbage results.
The default would be set to whatever the XML text() node
contains, because that is what you asked for.

    typedef Example1 {
       type uint32 {
           range "1 .. 10 | 100 .. 200";
       }
       default 7;
    }

    typedef Example2 {
       type union {
           type uint32 {
               range "1 .. 10";
           }
           type uint32 {
               range "100 .. 200";
           }
       }
       default 7;
    }

So if the typedef Example1 is used, then the default '7'
is applied, but if typedef Example2 is used, the
default '7' is silently ignored?  This is rather confusing.

I don't see using a named type should make any difference:

    typedef Num1 {
       type uint32 {
           range "1 .. 10 | 100 .. 200";
       }
       default 7;
    }

    typedef Example1 {
       type Num1;
    }

What about:

    typedef Example1 {
       type Num1;
       default 181;
    }

Is there any text needed about which typedef default
has precedence (181, not 7)?

Andy

---

From: Martin Bjorklund <[email-masked]>
Date: Thu, 11 Jun 2009 19:04:09 +0200 (CEST)

> case for union typedefs will be very confusing.

I don't see what is confusing.  Today, the text is not clear.  It
says (about the typedef's default statement, which I believe we are
discussing).

  If the base type has a default value, and the new derived type does
  not specify a new default value, the base type's default value is
  also the default value of the new derived type.

This is not clear - in the case of a union there is no "base type",
just a list of "member types".

/martin

---

From: Juergen Schoenwaelder <[email-masked]>
Date: Thu, 11 Jun 2009 19:15:47 +0200

On Thu, Jun 11, 2009 at 06:08:21PM +0200, Ladislav Lhotka wrote:
> Andy Bierman p????e v ??t 11. 06. 2009 v 07:33 -0700:
> 
> > 
> >     type union {
> >        type string;

+1

/js

-- 
Juergen Schoenwaelder           Jacobs University Bremen gGmbH
Phone: +49 421 200 3587         Campus Ring 1, 28759 Bremen, Germany
Fax:   +49 421 200 3103         <http://www.jacobs-university.de/>

---

From: Andy Bierman <[email-masked]>
Date: Thu, 11 Jun 2009 10:27:26 -0700

> just a list of "member types".

   typedef A {
     type uint32;
     default 5;
   }

   typedef B {
     type A;
   }

   typedef C {
     type union {
        type uint32;
        type string;
     }
     default fred;
   }

   typedef D {
     type C;
   }

   typedef E {
      type string;
      default fred;
   }

   typedef F {
      union {
         type uint32;
         type E;
      }
   }

   type      default
   ---------------------
     A         5
     B         5
     C         fred
     D         fred
     E         fred
     F         <none>

IMO, it is confusing that named types pass their
default sometimes (B, D) but not others (F).
It seems confusing that C and F do not produce the
same results.

So what is your proposed text?

Andy

---

From: Juergen Schoenwaelder <[email-masked]>
Date: Thu, 11 Jun 2009 21:43:11 +0200

>    type      default

C and F do not produce the same result since they are different. The
equivalent to C is this:

   typedef F {
      union {
         type uint32;
         type E;
      }
      default fred;
   }

I think we have the same with other type properties:

  typedef apple { type uint32; units "apples"; }
  typedef peach { type stirng; units "peaches"; }

  typedef fruits {
    union { type apple; type peach; }
  }

Again, fruits do not have an associated unit (I hope ;-) and I think
this makes sense.

/js

---

From: Andy Bierman <[email-masked]>
Date: Thu, 11 Jun 2009 15:41:59 -0700

> C and F do not produce the same result since they are different. The

OK -- I guess you are right.

The default for a typedef-stmt can only be valid if
there is an explicit default-stmt as a sub-statement
of typedef-stmt.  If a derived type is used, then
all parent types are checked the same way.
(Check the parent only if a direct derived type,
not a derived type within a union.)

    typedef G {
       type B;
    }

    typedef H {
      type G;
    }

default for type H is 5

Andy

---

From: Martin Bjorklund <[email-masked]>
Date: Mon, 22 Jun 2009 14:54:38 +0200 (CEST)

> Again, fruits do not have an associated unit (I hope ;-) and I think

I agree.  Would this text help in section 9.12:

  Any default values or units properties defined in the member types are
  not inherited to the union type.

/martin