Skip to content

module types as typelias type args are evaluated in the context of the alias's module, not where module is used #1712

Description

@HT154
open module currentModuleType4

import "pkl:test"
import "helpers/aliasHolder.pkl"

typealias Foo<T> = T? // aliasHolder.pkl contains only this same line

x: Int = 1

function fun(val: module?): Int = val?.x ?? -1
function fun1(val: aliasHolder.Foo<module>): Int = val?.x ?? -1
function fun2(val: Foo<module>): Int = val?.x ?? -1

res1 = fun(this)
res2 = fun1(this)
res3 = fun2(this)
res4 = test.catch(() -> fun(new Dynamic { x = "nope" }))
res5 = test.catch(() -> fun1(new Dynamic { x = "nope" }))
res6 = test.catch(() -> fun2(new Dynamic { x = "nope" }))

Expected res2 to not error, but instead:

–– Pkl Error ––
Expected value of type `aliasHolder`, but got type `currentModuleType4`.
Value: new ModuleClass { x = 1; res1 = 1; res2 = ?; res3 = ?; res4 = ?; res5 = ?; re...

xx | function fun1(val: aliasHolder.Foo<module>): Int = val?.x ?? -1
                                        ^^^^^^
at currentModuleType4#fun1 (file:///$snippetsDir/input/types/currentModuleType4.pkl)

xx | res2 = fun1(this)
            ^^^^^^^^^^
at currentModuleType4#res2 (file:///$snippetsDir/input/types/currentModuleType4.pkl)

xxx | renderer.renderDocument(value)
      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
at pkl.base#Module.output.text (pkl:base)

xxx | if (renderer is BytesRenderer) renderer.renderDocument(value) else text.encodeToBytes("UTF-8")
                                                                         ^^^^
at pkl.base#Module.output.bytes (pkl:base)

This shows that the module in aliasHolder.Foo<module> refers to the aliasHolder module, not the currentModuleType4 where module is actually written.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions