NullPointerException in YetiType.deriveOpaque and some questions to opaque types

5 views
Skip to first unread message

chrisichris

unread,
Apr 5, 2013, 3:30:44 AM4/5/13
to yeti...@googlegroups.com
Hi 

when I compile the following code I get a NPE. The code is not correct however I wanted to report the NullPointerException (the stacktrace is at the end):

typedef opaque promiseCollector = {
    mutex is ~Object,
    starting is () -> (),
    hasReceived is Ex ~Exception | Value () -> ()
};

_promiseCollectorUnwrap pc = pc as promiseCollector -> { 
                            mutex is ~Object,
                            starting is () -> (),
                            hasReceived is Ex ~Exception | Value () -> ()
                        };

One more question: what's the best way to unwrap an opaque type. Currently I do:

_promiseCollectorUnwrap = do pc: pc done as promiseCollector -> { 
                            mutex is ~Object,
                            starting is () -> (),
                            hasReceived is Ex ~Exception | Value () -> ()
                        };

Because this does not compile:
_promiseCollectorUnwrap pc = (pc is promiseCollector) as { 
                            mutex is ~Object,
                            starting is () -> (),
                            hasReceived is Ex ~Exception | Value () -> ()
                        };


And finally another question: Would it make sense to automatically generate the unwrap-function with the opaque typedef? Because often the 'hidden' type is quite complex and the unwrap function is just boilerplate code.

ie typedef opaque  someType = ~Object 

would be extended to

typedef opaque someType = ~Object;
unwrapOpaque_someType = do st: st done as someType -> ~Object;


The stacktrace of the NPE:

java.lang.NullPointerException
    at yeti.lang.compiler.YetiType.deriveOpaque(YetiType.java:1161)
    at yeti.lang.compiler.YetiType.opaqueCast(YetiType.java:1200)
    at yeti.lang.compiler.YetiAnalyzer.isOp(YetiAnalyzer.java:397)
    at yeti.lang.compiler.YetiAnalyzer.analyze(YetiAnalyzer.java:189)
    at yeti.lang.compiler.YetiAnalyzer.lambda(YetiAnalyzer.java:1165)
    at yeti.lang.compiler.YetiAnalyzer.lambdaBind(YetiAnalyzer.java:1123)
    at yeti.lang.compiler.YetiAnalyzer.singleBind(YetiAnalyzer.java:820)
    at yeti.lang.compiler.YetiAnalyzer.analSeq(YetiAnalyzer.java:1040)
    at yeti.lang.compiler.YetiAnalyzer.analyze(YetiAnalyzer.java:91)
    at yeti.lang.compiler.YetiAnalyzer.toCode(YetiAnalyzer.java:1817)
    at yeti.lang.compiler.Compiler.compile(Compiler.java:469)
    at yeti.lang.compiler.YetiTypeVisitor.getType(TypeAttr.java:500)
    at yeti.lang.compiler.YetiAnalyzer.toCode(YetiAnalyzer.java:1760)
    at yeti.lang.compiler.Compiler.compile(Compiler.java:469)
    at yeti.lang.compiler.YetiTypeVisitor.getType(TypeAttr.java:500)
    at yeti.lang.compiler.YetiAnalyzer.toCode(YetiAnalyzer.java:1760)
    at yeti.lang.compiler.Compiler.compile(Compiler.java:469)
    at yeti.lang.compiler.Compiler.compileAll(Compiler.java:195)
    at yeti.lang.compiler.eval$compileYetiFiles$._0(eval.yeti:334)
    at yeti.lang.compiler.eval$compileYetiFiles$.apply(eval.yeti:325)
    at code._0(<>:10)
    at code.apply(<>)
    at yeti.lang.compiler.eval._1(eval.yeti:98)
    at yeti.lang.compiler.eval.execClass(eval.yeti:76)
    at yeti.lang.compiler.eval$evaluateYetiCode$._0(eval.yeti:484)
    at yeti.lang.compiler.eval$evaluateYetiCode$.apply(eval.yeti:460)
    at yeti.lang.Fun2_.apply(Unknown Source)
    at yeti.lang.compiler.yeti.main(yeti.yeti:198)

Thanks,
Christian

Madis

unread,
Apr 5, 2013, 11:34:25 AM4/5/13
to yeti...@googlegroups.com

On Fri, 5 Apr 2013, chrisichris wrote:

> Hi�
> when I compile the following code I get a NPE. The code is not correct however I wanted to report
> the NullPointerException (the stacktrace is at the end):
>
> typedef opaque promiseCollector = {
> � � mutex is ~Object,
> � � starting is () -> (),
> � � hasReceived is Ex ~Exception | Value () -> ()
> };
>
> _promiseCollectorUnwrap pc = pc as promiseCollector -> {�
> � � � � � � � � � � � � � � mutex is ~Object,
> � � � � � � � � � � � � � � starting is () -> (),
> � � � � � � � � � � � � � � hasReceived is Ex ~Exception | Value () -> ()
> � � � � � � � � � � � � };
>
> One more question: what's the best way to unwrap an opaque type. Currently I do:
>
> _promiseCollectorUnwrap = do pc: pc done as promiseCollector -> {�
> � � � � � � � � � � � � � � mutex is ~Object,
> � � � � � � � � � � � � � � starting is () -> (),
> � � � � � � � � � � � � � � hasReceived is Ex ~Exception | Value () -> ()
> � � � � � � � � � � � � };
>
> Because this does not compile:
> _promiseCollectorUnwrap pc = (pc is promiseCollector) as {�
> � � � � � � � � � � � � � � mutex is ~Object,
> � � � � � � � � � � � � � � starting is () -> (),
> � � � � � � � � � � � � � � hasReceived is Ex ~Exception | Value () -> ()
> � � � � � � � � � � � � };

Won't replacing 'do pc: pc done' with 'id' work?
Some way to define module-local typedefs at top-level should be added
(here it would avoid the repeating the promiseCollector hidden type
without polluting the export typedefs namespace).

> And finally another question: Would it make sense to automatically generate the unwrap-function
> with the opaque typedef? Because often the 'hidden' type is quite complex and the unwrap function
> is just boilerplate code.
>
> ie typedef opaque �someType = ~Object�
>
> would be extended to
>
> typedef opaque someType = ~Object;
> unwrapOpaque_someType = do st: st done as someType -> ~Object;

Not sure, probably not by default, and local typedefs would make the
boilerplate minimal.

> The stacktrace of the NPE:

I'll look into it.

chrisichris

unread,
Apr 5, 2013, 1:25:54 PM4/5/13
to yeti...@googlegroups.com, ma...@cyber.ee



Won't replacing 'do pc: pc done' with 'id' work?

Works great thanks.
 
Some way to define module-local typedefs at top-level should be added
(here it would avoid the repeating the promiseCollector hidden type
without polluting the export typedefs namespace).

Sure this would help as well and have broather application than the default deconstructor.

Thanks for the answer
Christian
 
Reply all
Reply to author
Forward
0 new messages