Skip to content

compiler/checker: the compiler panics instead of returning a type-checking error with invalid default statement #941

@zapateo

Description

@zapateo

Consider this test:

"https://github.com/open2b/scriggo/issues/941": {
	sources: fstest.Files{
		"index.html": `{% var filters = filters default nil %}`,
	},
	main: native.Package{
		Name: "main",
		Declarations: native.Declarations{
			"filters": (*[]int)(nil),
		},
	},
},

instead of returning an error relative to the use of the untyped nil, it panics the type checker.

Note that this code:

"https://github.com/open2b/scriggo/issues/941": {
	sources: fstest.Files{
		"index.html": `{% var filters = filters default nil %}`,
	},
	expectedBuildErr: "use of untyped nil",
},

works as expected. The problem seems to be related to this code:

for i, rh := range rhs {
for j, ti := range rh {
if ti == nil {
continue
}
if ti.Nil() {
panic(tc.errorf(subExpr(nodeRhs[i], j == 0), "use of untyped nil"))
}
if j == 0 || ti.Untyped() {
tc.mustBeAssignableTo(ti, subExpr(nodeRhs[i], j == 0), rh[1].Type, false, nil)
}
}
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugBug: something already implemented does not work as it shouldtcheckerRelated to type checkertemplatesRelated to the template

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions