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

Using a basic type w/ no default along w/ computed types & basic types with defaults lead to invalid code being generated #144

Open
wwerner opened this issue Mar 26, 2020 · 1 comment

Comments

@wwerner
Copy link
Contributor

wwerner commented Mar 26, 2020

Example:

event SchemaDefined {
    type eventType
    timestamp occurredOn
    version eventVersion

    string foo
    string[] bar = {"baz","qux","quux"}

    int i = 4242
}

Resulting code:

package io.vlingo.examples.schemata.event;

import io.vlingo.lattice.model.DomainEvent;
import java.lang.String;

public final class SchemaDefined extends DomainEvent {
  public final String eventType;

  public final long occurredOn;

  public final int eventVersion;

  public final String foo;

  public String[] bar = new java.lang.String[] { "baz", "qux", "quux" };

  public int i = 4242;

  public SchemaDefined(final String foo, final String[] bar, final int i) {
    this.eventType = "SchemaDefined";
    this.occurredOn = System.currentTimeMillis();
    this.eventVersion = io.vlingo.common.version.SemanticVersion.toValue("0.0.1");
    this.foo = foo; 
    this.bar = bar; 
    this.i = i; }

  public SchemaDefined() {
    this.eventType = "SchemaDefined";
    this.occurredOn = System.currentTimeMillis();
    this.eventVersion = io.vlingo.common.version.SemanticVersion.toValue("0.0.1");}
}

Compilation error:

...event/SchemaDefined.java:[30,83] variable foo might not have been initialized
@VaughnVernon
Copy link
Contributor

@wwerner Both variables must be final. You should assign the defaults in the zero-arg ctor, not in the variable decl.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants