compile_fail_demo

package
v0.8.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 6, 2026 License: BSD-3-Clause Imports: 1 Imported by: 0

Documentation

Overview

This file deliberately fails to compile. It demonstrates the compile-time type-safety property the v2 generic API guarantees: you cannot read a Field declared for schema A through a View for schema B, and you cannot pass a value of the wrong wire type.

Run:

cd ~/work/lux/zap/v2 && go build ./_compile_fail_test/...

Expected output (Go 1.23+):

./cross_schema_field.go:NN:NN: cannot use AlphaFields.X (variable
  of type zapv2.Field[AlphaSchema, uint64]) as
  zapv2.Field[BetaSchema, uint64] value in argument to zapv2.Read

The directory name begins with an underscore so `go build ./...` at the v2 root skips it; only an explicit build path includes it, which is the test harness's job (see [TestCompileFail] in the adjacent compile_fail_test.go).

Index

Constants

This section is empty.

Variables

View Source
var (
	AlphaFields = struct {
		X zapv2.Field[AlphaSchema, uint64]
	}{X: zapv2.At[AlphaSchema, uint64](1)}

	BetaFields = struct {
		Y zapv2.Field[BetaSchema, uint64]
	}{Y: zapv2.At[BetaSchema, uint64](1)}
)

Functions

This section is empty.

Types

type AlphaSchema

type AlphaSchema struct{}

AlphaSchema is one schema...

func (AlphaSchema) Kind

func (AlphaSchema) Kind() zapv2.KindByte

func (AlphaSchema) Name

func (AlphaSchema) Name() string

func (AlphaSchema) Size

func (AlphaSchema) Size() int

type BetaSchema

type BetaSchema struct{}

BetaSchema is a different schema...

func (BetaSchema) Kind

func (BetaSchema) Kind() zapv2.KindByte

func (BetaSchema) Name

func (BetaSchema) Name() string

func (BetaSchema) Size

func (BetaSchema) Size() int

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL