tpl/collections: Fix handling of different interface types in Slice
authorBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
Tue, 2 Oct 2018 15:35:33 +0000 (17:35 +0200)
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
Tue, 2 Oct 2018 20:54:16 +0000 (23:54 +0300)
commit10ac2ec4466090957e1f6897906ddeb1e0b13673
treec0d6c875a2305a6e0dc2c6bdc30dcf8fc8253893
parentce264b936ce9f589bd889e18762881cff8bc9cd0
tpl/collections: Fix handling of different interface types in Slice

In Hugo `0.49` we improved type support in `slice`. This has an unfortunate side effect in that `resources.Concat` now expects something that can resolve to `resource.Resources`.

This worked for most situations, but when you try to `slice` different `Resource` objects, you would be getting `[]interface {}` and not `resource.Resources`. And `concat` would fail:

```bash
error calling Concat: slice []interface {} not supported in concat.
```

This commit fixes that by simplifying the type checking logic in `Slice`:

* If the first item implements the `Slicer` interface, we try that
* If the above fails or the first item does not implement `Slicer`, we just return the `[]interface {}`

Fixes #5269
hugolib/resource_chain_test.go
tpl/collections/collections.go
tpl/collections/collections_test.go