Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

text/template: can't evaluate field a in type *main.A #29137

Closed
mei-rune opened this issue Dec 7, 2018 · 3 comments
Closed

text/template: can't evaluate field a in type *main.A #29137

mei-rune opened this issue Dec 7, 2018 · 3 comments
Labels
FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done.
Milestone

Comments

@mei-rune
Copy link

mei-rune commented Dec 7, 2018

What version of Go are you using (go version)?

$ go version
go version go1.11.1 windows/amd64

Does this issue reproduce with the latest release?

Yes

What operating system and processor architecture are you using (go env)?

go env Output
$ go env
set GOARCH=amd64
set GOBIN=
set GOCACHE=C:\Users\xxxx\AppData\Local\go-build
set GOEXE=.exe
set GOFLAGS=
set GOHOSTARCH=amd64
set GOHOSTOS=windows
set GOOS=windows
set GOPATH=d:\developing\go\xxxxx;
set GOPROXY=
set GORACE=
set GOROOT=d:\tools\go_amd64
set GOTMPDIR=
set GOTOOLDIR=d:\tools\go_amd64\pkg\tool\windows_amd64
set GCCGO=gccgo
set CC=gcc
set CXX=g++
set CGO_ENABLED=1
set GOMOD=
set CGO_CFLAGS=-g -O2
set CGO_CPPFLAGS=
set CGO_CXXFLAGS=-g -O2
set CGO_FFLAGS=-g -O2
set CGO_LDFLAGS=-g -O2
set PKG_CONFIG=pkg-config
set GOGCCFLAGS=-m64 -mthreads -fmessage-length=0 -fdebug-prefix-map=C:\Users\xxx\AppData\Local\Temp\go-build794245338=/tmp/go-build -gno-record-gcc-switche
s

What did you do?

// You can edit this code!
// Click here and start typing.
package main

import (
 "fmt"
 "text/template"
 "os"
)

type A struct {
  Name string
}

func main() {
	var a *A = nil

	err := template.Must(template.New("default").Parse("{{.Name}}")).Execute(os.Stdout, a)
	if err != nil {
		fmt.Println(err)
	}
}

What did you expect to see?

template: default:1:4: executing "default" at <.Name>: nil pointer evaluating .Name

What did you see instead?

template: default:1:4: executing "default" at <.Name>: can't evaluate field Name in type *main.A

@mei-rune mei-rune closed this as completed Dec 7, 2018
@mei-rune mei-rune reopened this Dec 7, 2018
@agnivade
Copy link
Contributor

agnivade commented Dec 8, 2018

/cc @mvdan

@mvdan
Copy link
Member

mvdan commented Dec 9, 2018

Indeed seems like an edge case where the error could be clearer. Will send a CL for 1.13, since it's not a regression and doesn't seem important enough to merge this late during the freeze.

@mvdan mvdan self-assigned this Dec 9, 2018
@mvdan mvdan added this to the Go1.13 milestone Dec 9, 2018
@mvdan mvdan added the NeedsFix The path to resolution is known, but the work has not been done. label Dec 9, 2018
@gopherbot
Copy link

Change https://golang.org/cl/153341 mentions this issue: text/template: improve nil errors in evalField

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done.
Projects
None yet
Development

No branches or pull requests

4 participants