Skip to content

Commit

Permalink
compiler/checker: make the universal 'string' type a format type
Browse files Browse the repository at this point in the history
This change adds the 'propertyIsFormatType' property to the type info of
the 'string' type.
  • Loading branch information
gazerro committed Jun 24, 2021
1 parent 9170092 commit 4354956
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
4 changes: 2 additions & 2 deletions compiler/checker_expressions.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ var universe = typeCheckerScope{
"int64": {t: &typeInfo{Type: reflect.TypeOf(int64(0)), Properties: propertyIsType | propertyUniverse}},
"int8": {t: &typeInfo{Type: reflect.TypeOf(int8(0)), Properties: propertyIsType | propertyUniverse}},
"rune": {t: int32TypeInfo},
"string": {t: &typeInfo{Type: stringType, Properties: propertyIsType | propertyUniverse}},
"string": {t: &typeInfo{Type: stringType, Properties: propertyIsType | propertyIsFormatType | propertyUniverse}},
"true": {t: &typeInfo{Type: boolType, Properties: propertyUniverse | propertyUntyped, Constant: boolConst(true)}},
"uint": {t: &typeInfo{Type: uintType, Properties: propertyIsType | propertyUniverse}},
"uint16": {t: &typeInfo{Type: reflect.TypeOf(uint16(0)), Properties: propertyIsType | propertyUniverse}},
Expand Down Expand Up @@ -1891,7 +1891,7 @@ func (tc *typechecker) checkExplicitConversion(expr *ast.Call) *typeInfo {
var err error

switch {
case t.IsFormatType() && t.Type != arg.Type && !arg.IsUntypedConstant():
case t.Type != stringType && t.IsFormatType() && t.Type != arg.Type && !arg.IsUntypedConstant():
err = errTypeConversion
case arg.IsConstant():
k := t.Type.Kind()
Expand Down
2 changes: 1 addition & 1 deletion compiler/emitter_expressions.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ func (em *emitter) _emitExpr(expr ast.Expression, dstType reflect.Type, reg int8
}
typ := em.typ(expr.Args[0])
arg := em.emitExpr(expr.Args[0], typ)
markdownToHTML := ti.IsFormatType()
markdownToHTML := ti.IsFormatType() && ti.Type != stringType
if canEmitDirectly(convertType.Kind(), dstType.Kind()) {
if markdownToHTML {
em.changeRegisterConvertFormat(false, arg, reg, typ, convertType)
Expand Down

0 comments on commit 4354956

Please sign in to comment.