Skip to content

Vector.length doesn't propagate vector Warning with the length value #11570

@radeusgd

Description

@radeusgd

I'm not 100% sure if this is not intended behaviour, but I don't think it is correct.

Let's see the following code:

from Standard.Base import all

foo v =
    if v.length == 0 then "empty" else "not empty"

summarize name v =
    ws = Warning.get_all v . map .value
    IO.println "Value "+name+"="+v.to_display_text+'; warnings='+ws.to_text

type My_Warning
    Value msg

    to_display_text self -> Text = "My_Warning: "+self.msg
    to_text self -> Text = self.to_display_text

main =
    one = Warning.attach (My_Warning.Value "ONE") 1
    two = Warning.attach (My_Warning.Value "TWO") 2
    v = [one, two]
    summarize "v" v
    b1 = foo v
    summarize "b1" b1
    summarize "(v.at 0)" (v.at 0)

    p = Pair.new one two
    summarize "p" p
    b2 = foo p
    summarize "b2" b2
    summarize "(p.at 0)" (p.at 0)

Actual behaviour

I'm skipping the warnings being printed by the instrument as they are rather redundant. I wanted to have full control of displaying warnings on our values so I relied on good old println.

Value v=[1, 2]; warnings=[My_Warning: TWO, My_Warning: ONE]
Value b1=not empty; warnings=[]
Value (v.at 0)=1; warnings=[My_Warning: TWO, My_Warning: ONE]
Value p=Pair(1, 2); warnings=[My_Warning: TWO, My_Warning: ONE]
Value b2=not empty; warnings=[My_Warning: TWO, My_Warning: ONE]
Value (p.at 0)=1; warnings=[My_Warning: TWO, My_Warning: ONE]

Expected behaviour

IMO b1 should also have the 2 warnings attached, just like all the other values in this example.

I don't know if we have a clear specification for this, but I assumed that we had agreed on it that the Vector shouldn't really be special and it should propagate the warnings in the same way as any Atom does. From user's perspective both Pair and Vector are just a collection and the warnings should be propagated the same way.

If I check warnings on the vector v I get the 2 warnings. So if I then have a value that depends on v (by dataflow), it should inherit these warnings.

Interestingly, v.at 0 will actually inherit both warnings. It is correct, but moreover shows that the warnings are no longer part of the elements, they were already propagated to the whole vector and any operation depending on the vector should inherit them too.

Metadata

Metadata

Type

No type

Projects

Status

📤 Backlog

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions