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
runner-mei opened this issue Dec 7, 2018 · 3 comments

Comments

Projects
None yet
4 participants
@runner-mei
Copy link

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

@runner-mei runner-mei closed this Dec 7, 2018

@runner-mei runner-mei reopened this Dec 7, 2018

@agnivade

This comment has been minimized.

Copy link
Member

commented Dec 8, 2018

/cc @mvdan

@mvdan

This comment has been minimized.

Copy link
Member

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 label Dec 9, 2018

@gopherbot

This comment has been minimized.

Copy link

commented Dec 9, 2018

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.