Skip to content

Example in the readme fails to compile: some(3).or(7) #59

@AndrejMitrovic

Description

@AndrejMitrovic

Hi,

I'm trying this out with DMD v2.102.0 with the Includes a generic or range algorithm example on https://github.com/aliak00/optional#features:

import optional;

void main() {
    auto a = some(3);
    auto b = a.or(7);
}
lib/optional/source/optional/or.d(152,13): Error: expected return type of `int`, not `Optional!int`:
lib/optional/source/optional/or.d(150,13):        Return type of `int` inferred here.
lib/optional/source/optional/or.d(189,17): Error: template instance `optional.or.or!(Optional!int, int).or.or!(elseValue, Optional!int)` error instantiating
test.d(5,18):        instantiated from here: `or!(Optional!int, int)`

This works however:

    auto a = some(3);
    auto b = a.or(some(7));

Maybe just some() was missing?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions