This repository was archived by the owner on Dec 14, 2023. It is now read-only.
File tree Expand file tree Collapse file tree 3 files changed +11
-2
lines changed
Expand file tree Collapse file tree 3 files changed +11
-2
lines changed Original file line number Diff line number Diff line change @@ -136,7 +136,7 @@ func (c *compiler) Resolve(ident *ast.Ident) Value {
136136 value = c .NewConstValue (obj .Val (), obj .Type ())
137137
138138 default :
139- panic (fmt .Sprintf ("unreachable (%T)" , obj ))
139+ panic (fmt .Sprintf ("Could not handle type in compiler.Resolve(): (%T)" , obj ))
140140 }
141141
142142 data .Value = value
Original file line number Diff line number Diff line change @@ -6,6 +6,7 @@ package llgo
66
77import (
88 "code.google.com/p/go.tools/go/types"
9+ "code.google.com/p/go.tools/go/exact"
910 "fmt"
1011 "github.com/axw/gollvm/llvm"
1112 "go/ast"
@@ -534,12 +535,19 @@ func (c *compiler) VisitTypeAssertExpr(expr *ast.TypeAssertExpr) Value {
534535
535536func (c * compiler ) VisitExpr (expr ast.Expr ) Value {
536537 c .setDebugLine (expr .Pos ())
538+
537539 // Before all else, check if we've got a constant expression.
538540 // go/types performs constant folding, and we store the value
539541 // alongside the expression's type.
540542 if constval := c .typeinfo .Values [expr ]; constval != nil {
541543 return c .NewConstValue (constval , c .typeinfo .Types [expr ])
542544 }
545+ // nil-literals are parsed to Ident-nodes for some reason,
546+ // treat them like constant values here.
547+ // TODO nil literals should be represented more appropriately.
548+ if identval , valid := expr .(* ast.Ident ); valid && identval .Name == "nil" {
549+ return c .NewConstValue (exact .MakeUnknown (), c .typeinfo .Types [expr ])
550+ }
543551
544552 switch x := expr .(type ) {
545553 case * ast.BinaryExpr :
Original file line number Diff line number Diff line change @@ -56,7 +56,8 @@ func (c *compiler) NewValue(v llvm.Value, t types.Type) *LLVMValue {
5656
5757func (c * compiler ) NewConstValue (v exact.Value , typ types.Type ) * LLVMValue {
5858 switch {
59- case v .Kind () == exact .Nil :
59+ case v .Kind () == exact .Unknown :
60+ // TODO nil literals should be represented more appropriately once the exact-package supports it.
6061 llvmtyp := c .types .ToLLVM (typ )
6162 return c .NewValue (llvm .ConstNull (llvmtyp ), typ )
6263
You can’t perform that action at this time.
0 commit comments