Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conditionals in default bodies #91

@pbroadbery

Description

@pbroadbery

The code below compiles, but produces incorrect results --- 'hash' is referred to, but not given a value (it should come from %, in the same way as q). The problem is due to the conditional test '% has BasicType' not being noted correctly by the with body.

The function zz shows the same behaviour, but is less tractable, as the 'first' function depends on the value of T.

Trivial workaround for the first problem is to uncomment the commented line.

#include "foamlib"

I ==> SingleInteger;

Foo: Category == with {
    f: % -> I;
    q: % -> I;

    default {
        basic? ==> % has BasicType;
    f(n: %): I == {
       basic? => hash n;
       q n;
    }
--  if % has BasicType then { qq(a: %): I == never }
    zz(T: BasicType, x: %): T == if % has ListCategory T then first x else never;
    }
}

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions